weimha
asked on
Silverlight Custom Control Binding
I'm trying to make a silverlight custom control that contains a busy indicator and a content presenter. I want the busy indicator "IsBusy" property to be bound to a property in the datacontext of the content control content.
I've attached my control, generic.xaml and part of the view service that attaches they viewmodel to the view.
I want to bind the "IsBusy" property to a property called "IsReady" in the viewmodel. I will need to use a converter as well to inverse the IsReady property.
How would I do this?
I've attached my control, generic.xaml and part of the view service that attaches they viewmodel to the view.
I want to bind the "IsBusy" property to a property called "IsReady" in the viewmodel. I will need to use a converter as well to inverse the IsReady property.
How would I do this?
// My custom control
public class BusyControl : ContentControl
{
public BusyControl()
{
this.DefaultStyleKey = typeof(BusyControl);
}
public static readonly DependencyProperty IsBusyProperty = DependencyProperty.Register("IsBusy", typeof(bool), typeof(BusyControl), new PropertyMetadata(null));
public bool IsBusy
{
get { return (bool)GetValue(IsBusyProperty); }
set { SetValue(IsBusyProperty, value); }
}
}
// Generic.xaml
<ResourceDictionary xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Sdi.Silverlight.Core">
<Style TargetType="local:BusyControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:BusyControl">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<toolkit:BusyIndicator x:Name="PART_BusyIndicator" IsBusy="{TemplateBinding ?}">
<toolkit:BusyIndicator.BusyContentTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="Processing...Please Wait"></TextBlock>
</StackPanel>
</DataTemplate>
</toolkit:BusyIndicator.BusyContentTemplate>
<ContentPresenter x:Name="PART_Content" Content="{TemplateBinding Content}"/>
</toolkit:BusyIndicator>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
//In My View Service
public void ShowView(IViewModel viewModel, UserControl view, object parameters)
{
Guard.ArgumentNotNull(viewModel, "viewModel");
Guard.ArgumentNotNull(view, "view");
_currentViewModel = viewModel;
_currentView = view;
this.CurrentShell.CurrentContentContainer.Content = view;
viewModel.Load(parameters);
view.DataContext = viewModel;
OnPropertyChanged("CurrentView");
OnPropertyChanged("CurrentViewModel");
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, if you want to show this control before view model is built, you can use the 'fallbackvalue' to true for the visibility and once VM is built it will update with 'false'. How about that?
ASKER
somandha, I don't know what the "fallbackvalue" is. Tthe user's want to see the busy indicator.
Let me backup. Are you using SL4? I believe fallback is supported in SL4 only.
here is how you do it:
<TextBlock Text="{Binding FirstName, FallbackValue=N/A}" />
If the FirstName is not built yet, then N/A will be taken as the default (fallback) value
here is how you do it:
<TextBlock Text="{Binding FirstName, FallbackValue=N/A}" />
If the FirstName is not built yet, then N/A will be taken as the default (fallback) value
ASKER
somandha, the users want the busy indicator. They like it.
I've tried setting the binding like this and it just doesn't show the busy indicator
<toolkit:BusyIndicator x:Name="PART_BusyIndicator " IsBusy="{Binding Path=DataContext.IsReady}" >
I've tried setting the binding like this and it just doesn't show the busy indicator
<toolkit:BusyIndicator x:Name="PART_BusyIndicator
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This project has been put on hold. Thanks for your help.
ASKER
somandha: I don't want to show/hide the control. I want to use the busy indicator. Some of our viewmodels take a little while to load and we need to show our users that something is happening.
I'm trying to insert this into our current view/viewmodel/view service configuration.