Microsoft Developer Network > 포럼 홈 > Windows Presentation Foundation (WPF) > How to bind Properties.Settings to textboxes via XAML
질문하기질문하기
 

답변됨How to bind Properties.Settings to textboxes via XAML

답변

  • 2006년 10월 31일 화요일 오후 8:51lee d중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    create namespace mapping

    xmlns:l="clr-namespace:WindowsApplication1"

     

    Add a resource

    <ObjectDataProvider x:Key="odpsettings" ObjectType="{x:Type l:Properties.Settings}"></ObjectDataProvider>

     

    Bind the textblock(Setting1 is the property)

    <TextBlock Name="textps" Text="{Binding Source={StaticResource odpsettings}, Path=Default.Setting1}"></TextBlock>

  • 2006년 11월 1일 수요일 오전 10:24lee d중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    Binding b = new Binding("Setting1");

    b.Source = Properties.Settings.Default;

    text1.SetBinding(TextBlock.TextProperty, b);

모든 응답

  • 2006년 10월 31일 화요일 오후 8:51lee d중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    create namespace mapping

    xmlns:l="clr-namespace:WindowsApplication1"

     

    Add a resource

    <ObjectDataProvider x:Key="odpsettings" ObjectType="{x:Type l:Properties.Settings}"></ObjectDataProvider>

     

    Bind the textblock(Setting1 is the property)

    <TextBlock Name="textps" Text="{Binding Source={StaticResource odpsettings}, Path=Default.Setting1}"></TextBlock>

  • 2006년 10월 31일 화요일 오후 9:16Rod Yager 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Many thanks!!
  • 2006년 10월 31일 화요일 오후 9:29Rod Yager 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    How would you do this in code? Seems Interactive designer won't render the XAML even though the code works.
  • 2006년 11월 1일 수요일 오전 10:24lee d중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    Binding b = new Binding("Setting1");

    b.Source = Properties.Settings.Default;

    text1.SetBinding(TextBlock.TextProperty, b);

  • 2007년 1월 26일 금요일 오후 4:10Rod Yager 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Using the xaml example above, is it possible to assign the binding path to a setting?

     

    <ObjectDataProvider x:Key="AppSettings" ObjectType="{x:Type Task:Properties.Settings}"></ObjectDataProvider>

    Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RequestId}"

    I want to change it to something like this where SettingName would be equal to RequestId...

    Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AppSettings.Default.SettingName}"

     

    I don't get any errors but my data isn't showing up either

  • 2008년 10월 30일 목요일 오전 9:35Michael jp 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    There is a simpler way to bind to the application settings in xaml, without using the object data provider:

    create namespace mapping
    xmlns:Properties="clr-namespace:WindowsApplication1.Properties" 

    bind the textblock (Setting1 is your app settings property)
    <TextBlock Name="textps" Text="{Binding Path=Setting1, Source={x:Static Properties:Settings.Default}}"/>