Native ComboBox แสดงตัวเลือกไม่ถูกต้อง

แก้ไข: ดูเหมือนว่า ListPicker เป็นหนทางไป แต่ฉันมีปัญหาเพิ่มเติมกับรายละเอียดนั้น Microsoft.Phone.Controls.Toolkit ListPicker พ่น XamlParseException

ฉันมี ComboBox ต่อไปนี้ในรหัส:

<ComboBox x:Name="Result" Grid.Column="6" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black" Background="White">   
    <ComboBoxItem Content="Win" />  
    <ComboBoxItem Content="Place" />  
    <ComboBoxItem Content="Lose" />  
</ComboBox> 

แต่มันไม่แสดงอย่างที่ฉันคาดหวัง เมื่อคุณดรอปดาวน์ ComboBox ตัวเลือกจะไม่ปรากฏขึ้น มันก็เหมือนกับรายการว่างเปล่า ดูด้านล่าง:

ป้อนคำอธิบายรูปภาพที่นี่

อย่างไรก็ตาม เมื่อเลือกรายการแล้ว จะแสดงอย่างถูกต้องและส่งคืนดัชนี/รายการที่ถูกต้อง ดูด้านล่าง:

ป้อนคำอธิบายรูปภาพที่นี่

ฉันแน่ใจว่ามีบางอย่างที่เรียบง่ายที่ฉันพลาดไปแต่ไม่สามารถวางนิ้วลงบนมันได้

แก้ไข: ตกลงฉันกำลังโพสต์รหัสเต็มสำหรับสิ่งนี้ ฉันมีการควบคุมผู้ใช้ OddsRow ที่มีลักษณะดังนี้:

<UserControl xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"  x:Class="MojoPinBetOddsCalculator.OddsRow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480">

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="70"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50*"></ColumnDefinition>
            <ColumnDefinition Width="70*"></ColumnDefinition>
            <ColumnDefinition Width="30*"></ColumnDefinition>
            <ColumnDefinition Width="70*"></ColumnDefinition>
            <ColumnDefinition Width="70*"></ColumnDefinition>
            <ColumnDefinition Width="70*" ></ColumnDefinition>
            <ColumnDefinition Width="100*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <TextBlock x:Name="RowNumber" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
        <TextBox x:Name="OddsNumerator" Grid.Column="1" Width="90" Height="70" HorizontalAlignment="Center" TextAlignment="Center" VerticalAlignment="Center" MaxLength="3" InputScope="TelephoneNumber"></TextBox>
        <TextBlock x:Name="Slash" Grid.Column="2" Text="/" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
        <TextBox x:Name="OddsDenominator" Grid.Column="3" Width="90" Height="70" VerticalAlignment="Center" TextAlignment="Center" MaxLength="3" HorizontalAlignment="Center" InputScope="TelephoneNumber"></TextBox>
        <CheckBox x:Name="EachWay" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10,0,0,0" />
        <CheckBox x:Name="Place" Grid.Column="5" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="0" Width="71" Margin="10,0,0,0" Padding="0" />
        <ComboBox x:Name="Result" Grid.Column="6" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black" Background="White">
            <ComboBoxItem Content="Win" />
            <ComboBoxItem Content="Place" />
            <ComboBoxItem Content="Lose" />
        </ComboBox>
    </Grid>
</UserControl>

และจะแสดงในหน้าหลักดังนี้:

<phone:PhoneApplicationPage xmlns:my="clr-namespace:MojoPinBetOddsCalculator"  
    x:Class="MojoPinBetOddsCalculator.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="BET ODDS CALCULATOR" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="calculate" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>
        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" HorizontalAlignment="Stretch">
            <Grid x:Name="Scrollable">
                <ScrollViewer>
                <Grid x:Name="BettingGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="*"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid x:Name="BetList">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="70"></RowDefinition>
                            <RowDefinition Height="70"></RowDefinition>
                            <RowDefinition Height="70"></RowDefinition>
                            <RowDefinition Height="70"></RowDefinition>
                            <RowDefinition Height="70"></RowDefinition>
                            <RowDefinition Height="70"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="50*"></ColumnDefinition>
                            <ColumnDefinition Width="70*"></ColumnDefinition>
                            <ColumnDefinition Width="30*"></ColumnDefinition>
                            <ColumnDefinition Width="70*"></ColumnDefinition>
                            <ColumnDefinition Width="70*"></ColumnDefinition>
                            <ColumnDefinition Width="70*"></ColumnDefinition>
                            <ColumnDefinition Width="100*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="EW"  Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="0" Grid.Column="4" HorizontalAlignment="Center" />
                        <TextBlock Text="Place"  Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="0" Grid.Column="5" HorizontalAlignment="Center" />
                        <TextBlock Text="Result"  Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="0" Grid.Column="6" HorizontalAlignment="Center" />
                        <my:OddsRow Grid.Row="1" Grid.ColumnSpan="7" Row="1"/>
                        <my:OddsRow Grid.Row="2" Grid.ColumnSpan="7" Row="2"/>
                        <my:OddsRow Grid.Row="3" Grid.ColumnSpan="7" Row="3"/>
                        <my:OddsRow Grid.Row="4" Grid.ColumnSpan="7" Row="4"/>
                        <my:OddsRow Grid.Row="5" Grid.ColumnSpan="7" Row="5"/>
                        <my:OddsRow Grid.Row="6" Grid.ColumnSpan="7" Row="6"/>
                    </Grid>
                    <Grid x:Name="ControlsGrid" Grid.Row="1">
                        <Button x:Name="AddRowButton" Background="#BFFFFFFF" BorderBrush="#BFFFFFFF" Foreground="Black" Content="Add Row" FontSize="16" Click="AddRowButton_Click" Height="70" />
                    </Grid>
                </Grid>
                </ScrollViewer>
            </Grid>
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

ComboBox ทำงานแยกกัน และโค้ดสำหรับ OddsRow ทำงานตามที่คาดไว้... แยกกัน เมื่อรวมกันแล้วจะไม่แสดงรายการ

OddsRow.xaml.cs

public partial class OddsRow : UserControl
{
    private int m_Row;

    public OddsRow()
    {
        InitializeComponent();
    }

    public int Row
    {
        get
        {
            return m_Row;
        }
        set
        {
            m_Row = value;
            RowNumber.Text = m_Row + " - ";
        }
    }
}

person anothershrubery    schedule 11.04.2012    source แหล่งที่มา
comment
มันใช้งานได้สำหรับฉัน อาจเป็นสไตล์ที่กำหนดเองที่ทำให้ข้อความในกล่องคำสั่งผสมเป็นสีขาวหรือไม่   -  person Robaticus    schedule 12.04.2012
comment
อืม...ใช่ มันได้ผลตามที่คาดไว้เมื่อฉันแยกมันออกเป็นโปรเจ็กต์แยกกัน บางทีฉันอาจจะโพสต์มาร์กอัปแบบเต็มเพื่อดูว่ามีใครสังเกตเห็นสิ่งใดได้บ้าง   -  person anothershrubery    schedule 12.04.2012
comment
คุณกำลังทำอะไรบางอย่างกับ ComboBox ในโค้ดด้านหลังหรือไม่? เนื่องจากมาร์กอัปของคุณดูดี... คุณสามารถโพสต์ส่วนที่เกี่ยวข้องของโค้ดด้านหลังได้หรือไม่   -  person nemesv    schedule 12.04.2012
comment
เพิ่มโค้ดด้านหลัง ไม่มีอะไรน่าตื่นเต้นเกิดขึ้นที่นั่นอย่างแน่นอน ยังไม่ได้ทำอะไรเลยในโค้ด MainPage AddRowButton มีเพียงตัวจัดการเหตุการณ์ว่างสำหรับนาที   -  person anothershrubery    schedule 12.04.2012


คำตอบ (1)


สำหรับความรักในทุกสิ่ง โปรดอย่าใช้ ComboBox หุ้น ใช้ ListPicker มันจะทำให้แอปพลิเคชันของคุณดูสอดคล้องกับ Metro UI มากขึ้น

person Den Delimarsky    schedule 11.04.2012
comment
ฉันจะดู ListPicker เมื่อมีโอกาส ได้ดูมันอย่างรวดเร็วและได้รับ InvalidProgramException แต่ฉันแน่ใจว่ามันจัดเรียงได้อย่างง่ายดายด้วยการดูที่ดีกว่า - person anothershrubery; 12.04.2012
comment
ถ้าฉันมีปุ่ม +10 ฉันจะคลิกเพื่อ @Dennis ตอบ... โปรด อย่า ใช้ตัวควบคุม ComboBox และไปที่ ListPicker!!! - person Pedro Lamas; 12.04.2012
comment
ฉันทำเครื่องหมายว่านี่เป็นคำตอบเนื่องจากดูเหมือนว่าจะเป็นเส้นทางที่ถูกต้องในการลงไป แต่ฉันมีปัญหาเพิ่มเติมกับ ListPicker โดยมีรายละเอียดอยู่ที่ stackoverflow.com/questions/10155688/ - person anothershrubery; 14.04.2012