我正在尝试学习和理解 c# 中的功能区控件,尤其是数据绑定,但在实现 RibbonComboBox 时收到许多我无法解决的警告。我已设法删除错误消息,但警告仍然存在。我该如何解决?
相关文件如下所示,我删除了无关信息以简化它们。
这是 XAML 文件 - MainWindow.xaml:
<RibbonWindow x:Class="MyProject.MainWindow"
...
xmlns:local="clr-namespace:MyProject"
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
mc:Ignorable="d"
Title="MyProject" Height="450" Width="800" x:Name="MyProjectControl" >
<Grid>
<Ribbon DockPanel.Dock="Top" x:Name="Ribbon">
<RibbonTab Header="Home" >
<RibbonGroup Header="Shapes" Width="160">
<RibbonComboBox x:Name="cbShape" Height="Auto" Width="Auto" Label="Shape" VerticalAlignment="Center">
<RibbonGallery x:Name="shapeComboBox" SelectedItem="{Binding Path=Shape, UpdateSourceTrigger=PropertyChanged, Mode=OneWay, diag:PresentationTraceSources.TraceLevel=High}" >
<RibbonGalleryCategory x:Name="shapeList" ItemsSource="{Binding Path=Shape, Mode=OneWay}" />
</RibbonGallery>
</RibbonComboBox>
</RibbonGroup>
</RibbonTab>
</Ribbon>
</Grid>
</RibbonWindow>
它背后的代码 - MainWindow.xaml.cs:
using System.Collections.Generic;
using System.Windows.Controls.Ribbon;
namespace MyProject
{
public partial class MainWindow : RibbonWindow
{
public MainWindow()
{
InitializeComponent();
InitializeLists();
this.DataContext = new RibbonSettings();
}
private void InitializeLists()
{
List<string> MyShapes = new List<string>
{
"Square", "Circle", "Ellipse", "Triangle", "Pentagon"
};
shapeList.ItemsSource = MyShapes;
}
}
}
SMILET
相关分类