G
Gordon Padwick
I'm creating a WPF application that displays data from an Access table in a
ListBox that has four columns. A user can click one of four RadioButtons to
select on which column the data is sorted. All works well so far.
Now, I want to change the order of the columns in the ListBox, so that the
column on which the data is sorted is always the left-most. That's where I
running into a problem.
The format and content of the ListBox is controlled by
ItemTemplate="{StaticResource PlantTemplate}". PlantTemplate is a
DataTemplate (defined as a Grid resource) like this:
<Grid
. . . .
<Grid.Resources>
<DataTemplate x:Key="PlantTemplate">
<Grid
Name="plantListGrid">
<Grid.ColumnDefinitions>
ColumnDefinition Width="150"/>
. . . .
</Grid.ColumnDefinitions>
<TextBlock
Name="textColumn0"
Text="{Binding Path=txtCommonName}"
Grid.Column="0"/>
<TextBlock
. . . .
<TextBlock
. . . .
<TextBlock
. . . .
</Grid>
</DataTemplate>
</Grid.Resources>
. . . .
</Grid>
I have tried unsuccessfully to write code-behind that changes the Text= and
Grid.Column= items in the four TextBlocks when a user clicks a RadioButton
to select the column used for sorting. I haven't been able to find a way to
access the Text and Grid.Column values from code-behind.
I have also considered having four separate DataTemplates (with different
names) and switching between templates when a user clicks a RadioButton, but
don't know how to that.
I'll appreciate any help in solving this problem. Perhaps there is a better
approach?
Gordon Padwick
ListBox that has four columns. A user can click one of four RadioButtons to
select on which column the data is sorted. All works well so far.
Now, I want to change the order of the columns in the ListBox, so that the
column on which the data is sorted is always the left-most. That's where I
running into a problem.
The format and content of the ListBox is controlled by
ItemTemplate="{StaticResource PlantTemplate}". PlantTemplate is a
DataTemplate (defined as a Grid resource) like this:
<Grid
. . . .
<Grid.Resources>
<DataTemplate x:Key="PlantTemplate">
<Grid
Name="plantListGrid">
<Grid.ColumnDefinitions>
ColumnDefinition Width="150"/>
. . . .
</Grid.ColumnDefinitions>
<TextBlock
Name="textColumn0"
Text="{Binding Path=txtCommonName}"
Grid.Column="0"/>
<TextBlock
. . . .
<TextBlock
. . . .
<TextBlock
. . . .
</Grid>
</DataTemplate>
</Grid.Resources>
. . . .
</Grid>
I have tried unsuccessfully to write code-behind that changes the Text= and
Grid.Column= items in the four TextBlocks when a user clicks a RadioButton
to select the column used for sorting. I haven't been able to find a way to
access the Text and Grid.Column values from code-behind.
I have also considered having four separate DataTemplates (with different
names) and switching between templates when a user clicks a RadioButton, but
don't know how to that.
I'll appreciate any help in solving this problem. Perhaps there is a better
approach?
Gordon Padwick