【问题标题】:problems with binding data to data templates inside a busyindicator将数据绑定到busyindicator内的数据模板的问题
【发布时间】:2012-09-13 00:02:09
【问题描述】:

我在 wpf 中有一些代码,因为我使用了 busyindicator 并且我设置了 datatemplete 现在我的问题是我在我的应用程序中使用了 mvvm 模式,我想在上面使用 busyindicator 但我不知道如何在里面绑定文本块busyindicaor 数据模板。我的代码看起来像

<extended:BusyIndicator Name="_busyIndicator">
    <extended:BusyIndicator.BusyContentTemplate>
        <DataTemplate>
            <StackPanel Margin="4">
                <TextBlock Text="Downloading Email" FontWeight="Bold" HorizontalAlignment="Center" Name="Dhaval"/>
                <StackPanel Margin="4">
                    <TextBlock Text="Downloading message 4/10..."/>
                    <ProgressBar Value="40" Height="15" x:Name="Progress_Dhaval"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </extended:BusyIndicator.BusyContentTemplate>

【问题讨论】:

  • 在模板中绑定或者从模板中绑定完全一样,你只要写Text="{Binding YourProperty}" =)
  • 在我编写普通绑定时它不起作用。
  • 我在您的数据模板中看不到任何绑定
  • 假设 textblock 文本属性现在已绑定......告诉我。

标签: c# wpf binding busyindicator


【解决方案1】:

您可以将绑定与RelativeSource 一起使用。

在您的 ViewModel 中添加此属性:

        private string _busyText;
        public string BusyText
        {
            get { return _busyText; }
            set { _busyText = value; RaisePropertyChanged(() => BusyText); }
        }

并改变这一行:

<TextBlock Text="Downloading message 4/10..."/>

关于这个:

<TextBlock Text="{Binding Path=DataContext.BusyText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />

【讨论】:

  • 这就是我想要的,非常感谢 kmatyaszek。
猜你喜欢
  • 2011-09-07
  • 1970-01-01
  • 2022-01-21
  • 2013-09-17
  • 1970-01-01
  • 2017-12-25
  • 1970-01-01
  • 2011-07-28
  • 1970-01-01
相关资源
最近更新 更多