Hi,
Do you have any idea why the Grid.ColumnDefinition's Width within DataTemplate is not working and how I can fix this?
Here is the line of code:
<UserControl.Resources><DataTemplate x:Key="datatemplate_opencompany_itemx"><!-- template for the items in the OpenCompany List. The Background/ container is defined elsewhere, we define the bindings and textfield (so, only content) here.--><Grid Background="Transparent" Height="Auto" Width="Auto"><Grid.ColumnDefinitions><ColumnDefinition Width="{Binding WidthLength}"/><ColumnDefinition Width="*"/><ColumnDefinition Width="25"/></Grid.ColumnDefinitions><Border HorizontalAlignment="Stretch" Padding="4" VerticalAlignment="Stretch" d:LayoutOverrides="Width" CornerRadius="{DynamicResource cornerRadius_default}" Margin="2,1,4,1" BorderThickness="1" SnapsToDevicePixels="True" Height="22"><Border.Background><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="{Binding Company, ConverterParameter=B, Converter={StaticResource CompanyColorConverter}}" Offset="1"/><GradientStop Color="{Binding Company, ConverterParameter=Neutral, Converter={StaticResource CompanyColorConverter}}"/></LinearGradientBrush></Border.Background><Border.BorderBrush><LinearGradientBrush><!-- Workaround, for some reason a solidcolorbrush with bindings to the company color do not show up. So we'll just create a gradient from and to
the very same color. Which works just fine.--><GradientStop Color="{Binding Company, ConverterParameter=Line, Converter={StaticResource CompanyColorConverter}}" Offset="1"/><GradientStop Color="{Binding Company, ConverterParameter=Line, Converter={StaticResource CompanyColorConverter}}"/></LinearGradientBrush></Border.BorderBrush><!--PBI 90848: Changed the Company.Number to Company.Database to display the database name instead of company number--><TextBlock Text="{Binding Company.Database}" Width="Auto" Foreground="White" VerticalAlignment="Center" FontFamily="{DynamicResource font_default}" FontSize="12" FontWeight="Bold" HorizontalAlignment="Left"/></Border><controls:ExtendedTextBlock Text="{Binding Company.Name}" HorizontalAlignment="Stretch" VerticalAlignment="Center" FontFamily="{DynamicResource font_default}" FontSize="12" Grid.Column="1"/><Button x:Name="button" ToolTip="{Binding RemoveText}" cal:Message.Attach="[Event Click]=[Action DeleteCompanyCommand]" HorizontalAlignment="Center" Grid.Column="2" Template="{DynamicResource button_small_flat}" Visibility="Collapsed" VerticalAlignment="Center" ><Path Data="{DynamicResource icon_cross}" Height="12" Stretch="Fill" Width="12" Fill="{DynamicResource solid_red}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"/></Button></Grid><DataTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><!-- the delete button should only be show on a MouseOver --><Setter Property="Visibility" TargetName="button" Value="Visible"/></Trigger></DataTemplate.Triggers></DataTemplate></UserControl.Resources>If you can notice in this line of code, I binded the width length to the WidthLength property from the ModelView.
<Grid.ColumnDefinitions><ColumnDefinition Width="{Binding WidthLength}"/><ColumnDefinition Width="*"/><ColumnDefinition Width="25"/></Grid.ColumnDefinitions> public GridLength WidthLength
{
get { return _widthLength; }
set
{
if (value != _widthLength)
{
_widthLength = value;
NotifyOfPropertyChange(() => WidthLength);
}
}
}I tried this binding approach outside the DataTemplate and it is working properly.
Any suggestions?
Thank you!