簡體   English   中英

具有自定義控件屬性的Xaml ThemeResource imagebrush綁定

[英]Xaml ThemeResource imagebrush binding with custom control property

我目前正在使用我使用主題資源字典的Windows UWP應用程序。

我的主題字典中有

<ResourceDictionary.ThemeDictionaries>
    <!-- Light Theme resources -->
    <ResourceDictionary x:Key="Light">
        ...
        <ImageBrush x:Key="Hamburger" ImageSource="Assets/Images/DarkHamburger.png"/>
        ...
    </ResourceDictionary>
    <!-- Dark Theme resources -->
    <ResourceDictionary x:Key="Dark">
        ...
        <ImageBrush x:Key="Hamburger" ImageSource="Assets/Images/LightHamburger.png"/>
        ...
</ResourceDictionary.ThemeDictionaries>

和自定義控件屬性

public ImageBrush toggleButtonImage
    {
        get { return base.GetValue(toggleButtonImageProperty) as ImageBrush; }
        set { base.SetValue(toggleButtonImageProperty, value); }
    }
    public static readonly DependencyProperty toggleButtonImageProperty =
        DependencyProperty.Register("toggleButtonImage", typeof(ImageBrush), typeof(HomeHeaderControl), null);

最后,如果我寫這個,它就可以了

<HomeHeaderControl.toggleButtonImage>
     <ImageBrush  Stretch="UniformToFill" ImageSource="Assets/Images/LightHamburger.png"/>
</HomeHeaderControl.toggleButtonImage>

但是主題資源綁定不起作用

toggleButtonImage="{ThemeResource Hamburger}"

除ImageBrush之外,其他綁定均有效。 任何幫助將不勝感激。

您將必須使用絕對路徑和位圖圖像

<ResourceDictionary.ThemeDictionaries>
<!-- Light Theme resources -->
<ResourceDictionary x:Key="Light">
    ...
    <BitmapImage x:Key="Hamburger" ImageSource="ms-appx:///Assets/Images/DarkHamburger.png"/>
    ...
</ResourceDictionary>
<!-- Dark Theme resources -->
<ResourceDictionary x:Key="Dark">
    ...
    <BitmapImage x:Key="Hamburger" ImageSource="ms-appx:///Assets/Images/LightHamburger.png"/>
    ...

謝謝大家,我發現了失蹤者。 我在ImageSource中使用相對路徑。

我使用-> <ImageBrush x:Key="Hamburger" ImageSource="ms-appx:///Assets/Images/DarkHamburger.png"/>並對其進行了修復。

暫無
暫無

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

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