2012-04-11 129 views
1

编辑:看来ListPicker是要走的路,但我有更多的问题与详细Microsoft.Phone.Controls.Toolkit ListPicker throws XamlParseException本土组合框不显示选择正确

我有以下代码组合框:

<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> 

但它并不像我预期的那样显示。当你下拉组合框时,选项不会出现,就像空项目一样。见下文:

enter image description here

然而,当一个项目被选中时,它显示正确并返回正确的索引/项目。请看下图:

enter image description here

我敢肯定有一些简单的我已经错过了,但不能把我的手指上。

编辑:好吧我张贴完整的代码。我有一个用户控制,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> 

而且它显示在的MainPage像这样:

<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> 

分别组合框的作品,也是代号为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 + " - "; 
     } 
    } 
} 
+2

这对我很好。它可能是一种使组合框中的文本变成白色的自定义样式吗? – Robaticus 2012-04-11 20:55:23

+0

嗯......是的,当我把它放到一个单独的项目中时,它可以正常工作。也许我会张贴完整的标记,看看有没有人能发现任何东西。 – anothershrubery 2012-04-11 21:01:09

+0

确定更新完整标记。 – anothershrubery 2012-04-11 21:11:07

回答

2

一切的爱,请不要使用股票组合框。使用类似ListPicker的东西。它将使您的应用程序看起来与Metro UI更加一致。

+0

当我有机会时,我会查看ListPicker。有一个快速的看看它,并得到了一个'InvalidProgramException',但我相信这是很容易排序,更好地看看它。 – anothershrubery 2012-04-11 21:59:21

+1

如果我有一个按钮“+10”,我会点击它@Dennis回答...请**不要**使用组合框控件,并去ListPicker! – 2012-04-12 09:45:08

+0

我标记为答案,因为它似乎是正确的轨道,但我有'ListPicker'的进一步的问题,详细在http://stackoverflow.com/questions/10155688/microsoft-phone-controls-工具包 - listpicker抛出,xamlparseexception – anothershrubery 2012-04-14 17:23:58