Question

i have some code in wpf in that i have used busyindicator and i set datatemplete now my problem is that i used mvvm pattern in my applicaton and i want to used busyindicator on that but i don't know how to binding textblock inside busyindicaor datatemplete.my code look like

<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>

Was it helpful?

Solution

You can use Binding with RelativeSource.

Add in your ViewModel this property:

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

And change this line:

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

on this one:

<TextBlock Text="{Binding Path=DataContext.BusyText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top