Reputation: 771
I created a ListView with 3 Columns, that stores a splitted log in it (My last question).
The Column for Date/Time gets it's size by a Double in my ViewModel. I also added a button that changes this size.
Normally it's set to "Double.NaN" for Autosize, but when you deactivate that button, the width is set to 0. That works fine, but when I resize the column manually, it won't change it's size anymore, even tho the binding value changes.
This is the code in my ListView.
private void HideDate(object obj)
{
// FillListView(false);
DateWidth = 0;
}
private void ShowDate(object obj)
{
// FillListView();
DateWidth = Double.NaN;
}
I use a Messenger to trigger these methods, it works fine. This is my xaml for the ListView:
<ListView ItemsSource="{Binding LogEventList}">
<ListView.Resources>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Padding" Value="4,0,0,0" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Date/Time" DisplayMemberBinding="{Binding Date}" Width="{Binding DateWidth}"/>
<GridViewColumn Header="Category" DisplayMemberBinding="{Binding Category}" Width="Auto" />
<GridViewColumn Header="Event" DisplayMemberBinding="{Binding Event}" Width="Auto" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
Can I somehow tell the ListView to use DateWidth whenever it changes, as it seems to get another unchangeable property on a manual resize
Upvotes: 0
Views: 348
Reputation: 12276
When you set a value on a property that will effectively overwrite any binding on that property. Unless the property is marked to bind twoway by default or you bind twoway.
Further explanation and example code
When the user drags a column I should think that process sets a value on width. Which will have the effect explained above.
The first thing to try is changing your binding to:
Width="{Binding DateWidth, Mode=TwoWay}"
You haven't explained your viewmodel fully so other changes might be necessary to make your app behave as expected.
Upvotes: 1