What I want to achieve is, to create a style for a TextBlock Control which scales in height on mouseover depending on the amount of items which are being hold by the TextBlock.
My approach is to take the item amount and pass it to a converter which gives returns the TextBlock.Height * items.count but I'm having troubles achieving this. Also I want this style to only trigger for one column of my ListView and not for all but I haven't thought about how to do that yet.
Currently my XAML code looks like this:
<ListView ItemsSource="{Binding SwItemToPopulate}" Name="lvSoftware" DockPanel.Dock="Top" Margin="10,10,10,10" MinHeight="325" Height="Auto" Width="Auto">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Height">
<Setter.Value>
<Binding
Path="Dependencies.Count"
Converter="{StaticResource ItemCountToTextBoxHeightConverter}"
ConverterParameter="TextBlock.Height" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Dependencies">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Dependencies}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
and this is my converter:
namespace test.Converter
{
class ItemCountToTextBoxHeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(double))
throw new InvalidOperationException("The target must be an Integer");
int tbHeight = (int)parameter;
return (Double)value * tbHeight;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
If I set a Brakepoint to the Converter I can see that the value parameter is 0 and the parameter is TextBlock.Height is this because my binding is wrong or is this not even possible what I'm trying to do?
Edit I'm using a Tooltip now to achieve this. Thank all for the great comments and answers!
TextBlock
isn't designed to handle this scenario. You should use ItemsControl
instead.
Changing the GridViewColumn.CellTemplate
to a ItemsControl
would achieve this.
Having said that, try using TextBlock.ActualHeight
and not Height
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments