基本上我有一个名为“Exercise”的道具抽象类。它有两个子类“Cardio”和“Strength”,它们具有不同的属性。我现在正在开发的页面的目的是允许用户通过修改距离(对于有氧运动类型)和次数(对于力量类型)等内容来设置锻炼。我只能实现显示每个的目标子类的数据模板与列表框()。 我在 ListBox.Resources 中实现了一些样式代码,它看起来很完美,但是,我根本无法单击组合框。我已经附上了一些代码,我是个新手,所以我非常感谢任何帮助,谢谢!
另外:我还没有为组合框添加任何选择选项
代码:
<ListBox x:Name="exPanels" IsHitTestVisible="False" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Center" BorderThickness="0" Margin="0,20,0,0"
SelectedItem="{Binding SelectedObject}">
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
<DataTemplate DataType="{x:Type data:Cardio}">
<Border Padding="10" BorderBrush="LightGray" BorderThickness="1">
<Grid Width="585" HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Name="Name" Height ="auto"/>
<RowDefinition Name ="Type" Height ="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" Grid.Row="0"
Grid.Column="0" FontSize="20"/>
<TextBlock Text="Distance:" Grid.Row="1"
Grid.Column="0"/>
<ComboBox Grid.Row="1"
Grid.Column="1"/>
</Grid>
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type data:Strength}">
<Border Padding="10" BorderBrush="LightGray" BorderThickness="1">
<Grid x:Name="itembox" Width="585" HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Name="Name" Height ="auto"/>
<RowDefinition Name ="Type" Height ="auto"/>
<RowDefinition Name ="Difficulty" Height ="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" Grid.Row="0"
Grid.Column="0" FontSize="20"/>
<TextBlock Text="Sets:" Grid.Row="1"
Grid.Column="0"/>
<ComboBox Grid.Row="1"
Grid.Column="1"/>
<TextBlock Text="Reps:" Grid.Row="2"
Grid.Column="0"/>
<ComboBox Grid.Row="2"
Grid.Column="1"/>
</Grid>
</Border>
</DataTemplate>
</ListBox.Resources>
</ListBox>
要解决 ListBox 中非交互式 ComboBox 控件的问题,请确保将 ListBox 的 IsHitTestVisible 属性设置为 True。另外,检查数据绑定,检查样式和代码,并在必要时进行调试。
<ListBox x:Name="exPanels" IsHitTestVisible="True" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Center" BorderThickness="0" Margin="0,20,0,0" SelectedItem="{Binding SelectedObject}">
...
</ListBox>
<ComboBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding YourCollectionProperty}" SelectedItem="{Binding YourSelectedValueProperty}"/>