Im trying, using Code-behind-FREE XAML-code, to resize GridViewColumn / column1
each time Button1
is pressed according to the newly brought data (Button1 should bring new data and resize column1
of the ListView at the same time, the code that updates the data is not written down here).
when executing no error appears, but the size of column1
wont change, even i try to send dump values instead of auto
, like 100
, to see if it changes it size, which means im not reaching the right value!
How can i reach width value of column1 in the Setter ? will this method work eventually or is another method necessary?
i've written a fully functional Code-Behind but now i have to do the analog-Code-behind-FREE due to MVVM-reasons, for comparison und reference you'll find it after the XAML code!
Thanks in Advance!
XAML-Code
<ListView.View>
<GridView x:Name="dataGridView1">
<GridView.Columns >
<GridViewColumn x:Name="column1" >
<ContentControl>
<Style>
<Style.Triggers>
<!--the resize will happen here by triggering using the button-->
<DataTrigger Binding="{Binding ElementName=Button1, Path=IsPressed}" Value="True">
<Setter Property="GridViewColumn.Width" Value="auto" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=Button1, Path=IsPressed}" Value="False">
<Setter Property="GridViewColumn.Width" Value="auto" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl>
Code-behind-version (works fine, but must use the code-behind-FREE version!)
private void Button1_Click(object sender, RoutedEventArgs e)
{
foreach (GridViewColumn c in dataGridView1.Columns)
{
c.Width = 0; // Breite = 0
c.Width = double.NaN; // Resize
}
}