I have a new issue with the Label button now. The code below binds the view to the view model:
<Label Name="isImageValid" Content="Image not Created" Margin="0,7,1,0" Style="{StaticResource LabelField}"
Grid.ColumnSpan="2" Grid.Row="15" Width="119" Height="28" Grid.RowSpan="2"
Grid.Column="1" IsEnabled="True"
Visibility="{Binding isImageValid}" />
And the following is the code from my ViewModel:
private System.Windows.Visibility _isImageValid;
public System.Windows.Visibility isImageValid
{
get
{
return _isImageValid;
}
set
{
_isImageValid = value;
this.RaisePropertyChanged(() => this.isImageValid);
}
}
private void OnImageResizeCompleted(bool isSuccessful)
{
if (isSuccessful)
{
this.SelectedStory.KeyframeImages = true;
isImageValid = System.Windows.Visibility.Visible;
}
else
{
this.SelectedStory.KeyframeImages = false;
}
}
The Label is meant to stay hidden until “OnImageResizeCompleted” is called, but for some reason the image is visible all the time. What would I need to change to hide it, please?
Your issue is not with the actual binding mode, a label doesn’t need two way binding because it doesn’t usually set its source.
As @blindmeis suggested, you should use a converter instead of returning a Visibility value directly from the viewmodel, there is one built into the framework you can use. You should also ensure your datacontext is set correctly, if it isn’t then the label won’t be able to bind to the specified property. Do you have other items on the same window that are binding correctly to the viewmodel? You should also check your output window for binding errors – they will be mentioned there. Finally you should also check that your property is notifying correctly – that is impossible to tell from the code you provided.
Your control/window should look something like this
and the C#: