我正在嘗試學(xué)習(xí)和理解 c# 中的功能區(qū)控件,尤其是數(shù)據(jù)綁定,但在實(shí)現(xiàn) RibbonComboBox 時(shí)收到許多我無法解決的警告。我已設(shè)法刪除錯(cuò)誤消息,但警告仍然存在。我該如何解決?相關(guān)文件如下所示,我刪除了無關(guān)信息以簡化它們。這是 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; } }}
帶有 RibbonComboBox 的 WPF 綁定警告
30秒到達(dá)戰(zhàn)場
2023-04-29 10:01:56