いくつかのページをナビゲートする簡単なUWPアプリケーションを作っているとします。ユーザーが設定ページから選択した背景に応じて、すべてのページに共通の背景が必要です。UWPバインディング:C#を使用したXAMLの背景の変更
私はコンボボックス(および変更する必要があるグリッドの背景)とSettingsPage.xaml
を持っている:
SettingsPage.xaml.cs
ファイルとのインタフェース
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ComboBox Name="ColourSelect" SelectionChanged="ComboBox_SelectionChanged">
<ComboBoxItem Name="Red">Red</ComboBoxItem>
<ComboBoxItem Name="Green">Green</ComboBoxItem>
<ComboBoxItem Name="Blue">Blue</ComboBoxItem>
</ComboBox>
</Grid>
:私は含まれて私のApp.xaml
を設定している
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Change background
if (Red.IsSelected) { } // Change to Red.png
else if (Green.IsSelected) { } // Change to Green.png
else if (Blue.IsSelected) { } // Change to Blue.png
}
背景のリソースが、私はSettings.xaml.cs
のC#にバインドする方法がわかりません。
<Application.Resources>
<Style TargetType="Grid" x:Key="CommonBackground">
<Setter Property="Background" Value="{ <!-- Some image. How to bind? --> }"
</Style>
</Application.Resources>
ユーザーの決定をアプリケーションリソースにバインドするにはどうすればよいですか?
ありがとうございます!
なぜ自分の色のテンプレートを与える - ウィンドウズ10のテーマ全体をサポートできるのですか? – Peter