我是WPF的新手,仍然试图在XAML中绕过绑定.
我想在my.settings中使用字符串集合的值填充组合框.我可以在这样的代码中做到这一点:
Me.ComboBox1.ItemsSource = My.Settings.MyCollectionOfStrings
......它有效.
我怎么能在我的XAML中做到这一点?可能吗?
谢谢
Enr*_*lio 19
是的,您可以(并且应该在大多数情况下)在XAML中声明绑定,因为这是WPF中最强大的功能之一.
在您的情况下,要将ComboBox绑定到您的一个自定义设置,您将使用以下XAML:
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="clr-namespace:WpfApplication1.Properties"
    Title="Window1">
    <StackPanel>
        <ComboBox
            ItemsSource="{Binding Source={x:Static p:Settings.Default}, Path=MyCollectionOfStrings}" />
    </StackPanel>
</Window>
请注意以下几个方面: