绑定让我发疯

发布于 2025-01-08 13:04:33 字数 2997 浏览 0 评论 0原文

编辑:

XAML:

<TextBlock Text="{Binding Path=CurrentShows}"  Grid.Row="1"/>

产生以下输出:

 SilverlightHelloWorld.Deserialize.schedule

XAML:

<TextBlock Text="{Binding Path=CurrentShows.Today}"  Grid.Row="1"/>

也不会

<TextBlock Text="{Binding Path=CurrentShows.Today.Date}"  Grid.Row="1"/>

在调试模式下

产生任何错误或输出。有什么建议吗?


OldStatement:

我这里有一个非常复杂的例子, 最好的是,我从我的代码开始。

这是我的代码隐藏:

Mainpage.xaml.cs

schedule currentshows;
    public schedule CurrentShows
    {
        protected set
        {
            if (currentshows != value)
            {
                currentshows = value;
                OnPropertyChanged("CurrentShows");
            }
        }
        get
        {
            return currentshows;
        }
    }

Schedule.cs

[XmlRoot]
    public class schedule : INotifyPropertyChanged 
    {
        public event PropertyChangedEventHandler PropertyChanged;


        DayCollection today;
        [XmlElement("DAY")]
        public DayCollection Today
        {
            set
            {
                if (today != value)
                {
                    today = value;
                    OnPropertyChanged("Today");

                }
            }
            get
            {
                return today;
            }
        }

        private void OnPropertyChanged(string p)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(p));
        }

    }

DayCollection.cs

    public class DayCollection : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        ObservableCollection<TimeCollection> timecol;
        [XmlElement("time")]
        public ObservableCollection<TimeCollection> TimeCol
        {
            set
            {
                if (timecol != value)
                {
                    timecol = value;
                    OnPropertyChanged("TimeCol");

                }
            }
            get
            {
                return timecol;
            }
        }

        string date;
        [XmlAttribute(AttributeName = "attr")]
        public string Date
        {
            set 
            {
                if (date != value)
                {
                    date = value;
                    OnPropertyChanged("Date");

                }
            }
            get
            {
                return date;
            }
        }

        private void OnPropertyChanged(string p)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(p));
        }

    }

我试图在我的 Xaml 中显示字符串属性“日期”。 但我只是没有得到任何解决方案。

我非常感谢这里的任何帮助,提前致谢!

Edit:

the XAML:

<TextBlock Text="{Binding Path=CurrentShows}"  Grid.Row="1"/>

produces following Output:

 SilverlightHelloWorld.Deserialize.schedule

the XAML:

<TextBlock Text="{Binding Path=CurrentShows.Today}"  Grid.Row="1"/>

nor

<TextBlock Text="{Binding Path=CurrentShows.Today.Date}"  Grid.Row="1"/>

produce any Error or ouput while being in debugmode.

Anysuggestions?


OldStatement:

I've got a quiet well complicated Example here,
the best will be, I am starting with my Code.

This is my Codebehind:

Mainpage.xaml.cs

schedule currentshows;
    public schedule CurrentShows
    {
        protected set
        {
            if (currentshows != value)
            {
                currentshows = value;
                OnPropertyChanged("CurrentShows");
            }
        }
        get
        {
            return currentshows;
        }
    }

schedule.cs

[XmlRoot]
    public class schedule : INotifyPropertyChanged 
    {
        public event PropertyChangedEventHandler PropertyChanged;


        DayCollection today;
        [XmlElement("DAY")]
        public DayCollection Today
        {
            set
            {
                if (today != value)
                {
                    today = value;
                    OnPropertyChanged("Today");

                }
            }
            get
            {
                return today;
            }
        }

        private void OnPropertyChanged(string p)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(p));
        }

    }

DayCollection.cs

    public class DayCollection : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        ObservableCollection<TimeCollection> timecol;
        [XmlElement("time")]
        public ObservableCollection<TimeCollection> TimeCol
        {
            set
            {
                if (timecol != value)
                {
                    timecol = value;
                    OnPropertyChanged("TimeCol");

                }
            }
            get
            {
                return timecol;
            }
        }

        string date;
        [XmlAttribute(AttributeName = "attr")]
        public string Date
        {
            set 
            {
                if (date != value)
                {
                    date = value;
                    OnPropertyChanged("Date");

                }
            }
            get
            {
                return date;
            }
        }

        private void OnPropertyChanged(string p)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(p));
        }

    }

I am trying to get the String-Property "Date" in my Xaml to Show-Up.
But I am just don't get any Solution.

I totally would appreciate any help here, Thanks in Advance !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ι不睡觉的鱼゛ 2025-01-15 13:04:33

我已将您的代码复制到一个项目中,如果您使用此行来设置 TextBlock 的绑定,它就可以工作,

<TextBlock Text="{Binding Today.Date}"  Grid.Row="1"/>

但我无法从您的代码中看出您如何设置外部数据绑定。这是我在 MainPage 构造函数中包含的内容

currentshows = new schedule();
currentshows.Today = new DayCollection();
currentshows.Today.Date = "hallo";
LayoutRoot.DataContext = currentshows;

,其中 LayoutRoot 是 TextBlock 的父级,即

<Grid x:Name="LayoutRoot">
 <TextBlock Text="{Binding Today.Date}"/> 
</Grid>

I've copied your code into a project and it works if you use this line instead to set up the TextBlock's binding

<TextBlock Text="{Binding Today.Date}"  Grid.Row="1"/>

but I cannot tell from your code how you are setting up the outer data binding. Here's what I included in the MainPage constructor

currentshows = new schedule();
currentshows.Today = new DayCollection();
currentshows.Today.Date = "hallo";
LayoutRoot.DataContext = currentshows;

where LayoutRoot is the parent of the TextBlock, i.e.

<Grid x:Name="LayoutRoot">
 <TextBlock Text="{Binding Today.Date}"/> 
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文