本文介绍了绑定Xaml WPF中的静态属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有一个类(Session),它包含静态属性。静态属性包含Brush类型属性(ForeGround)。我想在wpf xaml中的资源中绑定Foreground属性。

(Foreground ={Binding Source = {StaticResource session},Path = Object.ForeGround} )不起作用



我无法绑定Foreground属性。请帮助

以下是示例代码



Dear All,
I have a class (Session), which contain static property. Static property contain Brush type property (ForeGround). I want to bind Foreground property in a resource in wpf xaml.
(Foreground="{Binding Source={StaticResource session}, Path=Object.ForeGround}") does not work

I am unable to bind Foreground property. Please Help
Below is sample code

 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Session.Object = new Info() { ForeGround = Brushes.White };
        }

private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            //If I quick watch item. i got session object, and required foreground value is Ok.

            var item = this.FindResource("session");
        }
    }

   //*****************************************
    public class Session
    {
        public static Info Object
        {
            get;
            set;
        }
    }

    //**************************************
    public class Info
    {
        public Brush ForeGround
        {
            get;
            set;
        }
    }





这里是WPF XAML





and here is WPF XAML

<Window.Resources>
       <local:Session x:Key="session"/>
   </Window.Resources>
   <Grid removed="Gray">
       <Viewbox>
           <TextBlock Name="txt" Text="Hello Text" Foreground="{Binding Source={StaticResource session}, Path=Object.ForeGround}"/>
       </Viewbox>

   </Grid>

推荐答案



这篇关于绑定Xaml WPF中的静态属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:55