代码之家  ›  专栏  ›  技术社区  ›  WernerCD

WPF StringCollection+文本框

  •  0
  • WernerCD  · 技术社区  · 14 年前

    应用程序设置:renamesettings-system.collections.specialized.stringcollection-user-*文本墙”

    <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>
    

    字符串集合…我想把它绑定到一个文本框上,文本,以便查看/编辑。遵循我在这里和那里看到的类似模式:

    我尝试过文本框、文本块、标签(只显示单词“(collection)”)…我怎么能把这个包扎得优雅呢?

    1 回复  |  直到 14 年前
        1
  •  1
  •   WernerCD    14 年前

    我是个白痴…已切换到列表框项源…

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