XAML Bind control property to assigned style

sevi

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!

Steven Volckaert

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

XAML bind to a property with @

From Dev

Bind control to escaped property?

From Dev

How to bind property of a ObservableCollection in XAML

From Dev

Bind an Action to a property of a UserControl in XAML

From Dev

Bind a Property that is outside of an Itemscontrol in XAML

From Dev

How to bind a modified property to a control Windows Universal Apps (XAML/C#)

From Dev

Binding winform control property in XAML

From Dev

The style attribute is overriding the css property assigned with jquery

From Dev

JavaFX bind not property member to control

From Dev

How to bind control to object property?

From Dev

How to bind control to object property?

From Dev

How to bind text to my custom XAML control?

From Dev

Global resource does not apply style to control in xaml

From Dev

How to bind user control property to other property?

From Dev

Bind a property to another property of a custom control

From Dev

how to bind isselected property of tabitem in xaml

From Dev

Bind and render Visual property in WPF XAML

From Dev

Bind property of root to value of child element in XAML

From Dev

Pass another control as property value in XAML

From Dev

Override Control Template Property value in XAML

From Dev

how to access property of a custom control in XAML WPF

From Dev

bind CRL wrapper or bind direct dependency property on XAML element

From Dev

How to bind a property of control to another control's property

From Dev

How to bind a property of control to another control's property

From Dev

Bind CSS Style Property to Node in JavaFX

From Dev

Bind to wpf custom control dependency property for tooltip?

From Dev

How to Bind to Another Control Property in WPF

From Dev

How to bind data to a control's Visibility property

From Dev

Bind a custom type property to a custom control

Related Related

  1. 1

    XAML bind to a property with @

  2. 2

    Bind control to escaped property?

  3. 3

    How to bind property of a ObservableCollection in XAML

  4. 4

    Bind an Action to a property of a UserControl in XAML

  5. 5

    Bind a Property that is outside of an Itemscontrol in XAML

  6. 6

    How to bind a modified property to a control Windows Universal Apps (XAML/C#)

  7. 7

    Binding winform control property in XAML

  8. 8

    The style attribute is overriding the css property assigned with jquery

  9. 9

    JavaFX bind not property member to control

  10. 10

    How to bind control to object property?

  11. 11

    How to bind control to object property?

  12. 12

    How to bind text to my custom XAML control?

  13. 13

    Global resource does not apply style to control in xaml

  14. 14

    How to bind user control property to other property?

  15. 15

    Bind a property to another property of a custom control

  16. 16

    how to bind isselected property of tabitem in xaml

  17. 17

    Bind and render Visual property in WPF XAML

  18. 18

    Bind property of root to value of child element in XAML

  19. 19

    Pass another control as property value in XAML

  20. 20

    Override Control Template Property value in XAML

  21. 21

    how to access property of a custom control in XAML WPF

  22. 22

    bind CRL wrapper or bind direct dependency property on XAML element

  23. 23

    How to bind a property of control to another control's property

  24. 24

    How to bind a property of control to another control's property

  25. 25

    Bind CSS Style Property to Node in JavaFX

  26. 26

    Bind to wpf custom control dependency property for tooltip?

  27. 27

    How to Bind to Another Control Property in WPF

  28. 28

    How to bind data to a control's Visibility property

  29. 29

    Bind a custom type property to a custom control

HotTag

Archive