Reputation: 801
just need a little help with some databinding.
So I have an ObservableCollection of a custom object. The properties of the object are as shown:
/// <summary>
/// Name
/// </summary>
private string _name;
public string Name
{
get
{
return _name;
}
set
{
if (value != _name)
{
_name = value;
NotifyPropertyChanged("Name");
}
}
}
/// <summary>
/// Status
/// </summary>
private int _status;
public int Status
{
get
{
return _status;
}
set
{
if (value != _status)
{
_status = value;
NotifyPropertyChanged("Status");
}
}
}
/// <summary>
/// Visible information
/// </summary>
private Visibility _visible;
public Visibility Visible
{
get
{
return _visible;
}
set
{
if (value != _visible)
{
_visible = value;
NotifyPropertyChanged("Visible");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
And basically I have three TextBlocks, the first two of which have Text binded to Name and Status while the third has:
Visibility = {Binding Visible}
But whenever I want to toggle the visibility property, I can only toggle it from the Visible state to Collapsed, and then not again. My toggle looks like this:
ItemViewModel l = ((sender as LongListSelector).SelectedItem) as ItemViewModel;
MessageBox.Show(l.Visible.ToString());
if (l.Visible == Visibility.Collapsed)
l.Visible = Visibility.Visible;
else
l.Visible = Visibility.Collapsed;
Note: ItemViewModel is the custom class for the collection, ie.
ObservableCollection<ItemViewModel>
Obviously it's just a rough test, but still doesn't work. The messagebox is always showing "Visible" regardless of the real visibility state of the item. How can I get it to get the real value of Visibility?
If anyone has any idea, that would be great.
Thanks.
EDIT: Adding XAML for the Textblocks for clarity:
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="20"/>
<TextBlock Text="{Binding Status}" TextWrapping="Wrap" Margin="12,-6,280,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
<TextBlock x:Name="t1" Text="Test for visibility" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}" Visibility="{Binding Visible}"/>
Keep in mind these textblocks are encased within a stackpanel and a longlistselector so simply changing t1.Visible is out of the question.
Upvotes: 0
Views: 558
Reputation: 19872
The problem, after more investigation, ends up being that the property was being set by another branch of code.
Upvotes: 1