簡體   English   中英

綁定到App.xaml中的屬性

[英]Bind to property in App.xaml

我有一個快速的問題:我想綁定一個Solidcolorbrush,它位於App.xaml的資源中。 它具有分配給它的密鑰,但是如何從另一個頁面綁定到該屬性?

這是App.xaml本身:

<Application x:Class="Mplayer.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary>
        <Color x:Key="PrimaryAccentColor" A="255" R="3" G="169" B="244"/>
        <SolidColorBrush x:Key="PrimaryAccentBrush" Color="{StaticResource PrimaryAccentColor}"/>
        <Color x:Key="SecondaryAccentColor" A="255" R="3" G="169" B="244"/>
        <SolidColorBrush x:Key="SecondaryAccentBrush" Color="{StaticResource SecondaryAccentColor}"/>
        <Color x:Key="LightBackgroundColor" A="255" R="3" G="169" B="244"/>
        <SolidColorBrush x:Key="LightBackgroundBrush" Color="{StaticResource LightBackgroundColor}"/>
        <Color x:Key="DarkBackgroundColor" A="255" R="3" G="169" B="244"/>
        <SolidColorBrush x:Key="DarkBackgroundBrush" Color="{StaticResource DarkBackgroundColor}"/>
    </ResourceDictionary>
</Application.Resources>

如果然后有一個要綁定到PrimaryAccentColorBrush的頁面,該綁定將如何顯示?

我嘗試將綁定設置為{Binding Path={StaticResource PrimaryAccentColorBrush}} ,但是找不到它。

任何幫助將不勝感激=)

您不必使用Binding ,只需使用StaticResource ,就像您已經做的那樣:

Property="{StaticResource PrimaryAccentBrush}"

您幾乎已經擁有了……嘗試以下方法:

<TextBlock Background="{Binding Source={StaticResource PrimaryAccentColorBrush}}" />

盡管您的示例中似乎沒有PrimaryAccentColorBrush ...您是說PrimaryAccentBrush嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM