WPF StringCollection + TextBox

时间:2010-09-29 14:55:23

标签: c# wpf binding application-settings

ApplicationSetting:RenameSettings - System.Collections.Specialized.StringCollection - User - * wall of text“

<Application x:Class="app.App"
         ...
         xmlns:properties="clr-namespace:app.Properties" 
         StartupUri="MainWindow.xaml">
    <Application.Resources>
        <properties:Settings x:Key="Settings" />
    </Application.Resources>
</Application>

<Window x:Class="app.MainWindow"
        ...
        xmlns:p="clr-namespace:app.Properties"
        Height="{Binding Source={StaticResource Settings}, Path=Default.Height, Mode=TwoWay}" MinHeight="300"
        ...
        >

    <Window.Resources>
        <p:Settings x:Key="settings" />
    </Window.Resources>

    <Grid DataContext="{StaticResource settings}">
        <Menu ... ... />
        <Label ... />
        <TextBox Margin="12,129,12,12" Name="textBlock1"  
            Text="{Binding Source={StaticResource Settings}, Path=Default.RenameSettings, Mode=TwoWay}"/>
    </Grid>
</Window>

StringCollection ...我想将它绑定到TextBox,Text,以便查看/编辑。遵循我在这里和那里看到的类似模式:

我尝试过TextBox,TextBlock,Label(只显示单词“(Collection)”)...我怎样才能优雅地绑定它?

1 个答案:

答案 0 :(得分:1)

我是个白痴......切换到ListBox ItemsSource ......

    <ListBox Margin="12,129,12,12" Name="textBlock1"  
             ItemsSource="{Binding Source={StaticResource Settings}, Path=Default.RenameSettings, Mode=TwoWay}"/>