스타일의 값을 클래스의 값을 정의하는 클래스에 따라 수정할 수있는 일부 정적 클래스 (예 : 응용 프로그램의 기본 설정)에 바인딩 할 수 있습니다.
아래 앱에서 Settings.settings
파일에 FontSize
이라는 속성을 만들었습니다. 내가 XAML 파일에서 적절한 네임 스페이스를 추가하고 내가 원하는대로 지금에 결합 할 수 있습니다
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication1"
xmlns:prop="clr-namespace:WpfApplication1.Properties"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.Resources>
<Style TargetType="TextBlock" x:Key="myStyle">
<Setter Property="FontSize" Value="{Binding FontSize, Source={x:Static prop:Settings.Default}}" />
</Style>
</Grid.Resources>
<TextBlock Style="{DynamicResource myStyle}" Text="The quick brown fox jumped over the lazy dog." />
<TextBox Grid.Row="1" Text="{Binding FontSize, Source={x:Static prop:Settings.Default}, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</Window>
가 나는 TextBox
에 직접 값을 바인딩하지만 말할 것도 해당 인스턴스에 대한 뷰 모델에서 일부 제어 메커니즘, 강력히 권장합니다.
private void Application_Exit(object sender, ExitEventArgs e)
{
WpfApplication1.Properties.Settings.Default.Save();
}
: 설정을 저장하려면
마지막으로, 당신이해야 할 모든 응용 프로그램의 Exit
이벤트의 이벤트 핸들러, 예를 들어, 클래스의 Save
메서드를 호출입니다