我正在嘗試學習和理解 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; } }}
1 回答

SMILET
TA貢獻1796條經驗 獲得超4個贊
您所指的警告只是擴展的跟蹤信息。只要綁定按照您的預期工作,就沒有必要檢查它們。但是,如果您在輸出中看到System.Windows.Data 錯誤,則意味著您需要注意它的內容(在我的例子中,最常見的原因是屬性名稱中的拼寫錯誤)。
您可以通過更改WPF Trace Settings下的Data Binding設置,在 Options -> Debugging ->?
- 1 回答
- 0 關注
- 170 瀏覽
添加回答
舉報
0/150
提交
取消