Minustar
Minustar

Reputation: 1225

Grid ColumnDefinition.Width in DataTemplate

In my project, I've made a control that inherits from Control. It is called DialogHeader and, as its name stands, is for displaying a header on modal, non-resizable dialogs. In truth, it binds by default to its parent Window. The control has a property called IconLocation, i.e. whether the image should be displayed on the left or right side of the control's label:

[Image] [Label] -- or -- [Label] [Image]

The template used with DialogHeader is basically the following:

<ControlTemplate>
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition x:Name="COLN_Left" Width="auto" />
      <ColumnDefinition Width="auto" />
      <ColumnDefinition x:Name="COLN_Right" Width="*" />
    </Grid.ColumnDefinitions>

    <Image Grid.Column="0" Name="PART_Image" />
    <Separator Grid.Column="1"
               Visibility="Collapsed" Width="{TemplateBinding SpacerWidth}" />
    <TextBlock Grid.Column="2" Name="PART_Text" />
  </Grid>
  <ControlTemplare.Triggers>
    <Trigger Property="ImageLocation" Value="Right">
      <Setter TargetName="PART_Image" Property="Grid.Column" Value="2" />
      <Setter TargetName="PART_Text"  Property="Grid.Column" Value="0" />
      <!-- The following doesn't work! Help! -->
      <Setter TargetName="COLN_Left"  Property="Width"       Value="*" />
      <Setter TargetName="COLN_Right" Property="Width"       Value="auto" />
    </Trigger>
  </ControlTemplate.Triggers>
</ControlTemplate>

Simply put, when the ImageLocation property is set to Location.Right, the widths of COLN_Left and COLN_Right should be exchanged. So instead of [auto][auto][*], I should have [*][auto][auto].

How can I make this work from the ControlTemplate? If not, is there are way that doesn't involve using C# code?

Thank you in advance.

Upvotes: 1

Views: 1239

Answers (1)

brunnerh
brunnerh

Reputation: 185290

That part does work, it possibly is just not what you want i presume. Try to remove it and the result should be different.

Upvotes: 1

Related Questions