0

The thing I want to make When mouseover in grid Border Visibilty property value must change.

I have a grid with a 3 ColumnDefinition.

enter image description here

The code is

<Grid x:Name="grid1">
     <Grid.ColumnDefinitions>
          <ColumnDefinition Width="5*"/>
           <ColumnDefinition Width="27*"/>
           <ColumnDefinition Width="93*"/>
      </Grid.ColumnDefinitions>
      <Border Grid.Column="0" Background="Blue" Visibility="Hidden">
           <Border.Style>
                <Style>
                   <Style.Triggers>
                    <DataTrigger Binding="{Binding IsMouseOver , RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}" Value="True">
                     <Setter Property="Border.Visibility" Value="Visible" />
                     </DataTrigger>
                     </Style.Triggers>
                   </Style>
               </Border.Style>
          </Border>
        <Image  Grid.Column="1" />
         <TextBlock Grid.Column="2" />

   </Grid>

When mouseover the grid nothing is happen.so This codes not working

eoweww
  • 117
  • 2
  • 11
  • 2
    Your DataTrigger use `IsReadOnly` as property. So what do you expect? – Clemens Oct 17 '16 at 09:22
  • If the default `Grid` has `IsReadOnly` property, you must be using a future .NET framework. – Jai Oct 17 '16 at 09:26
  • @Clemens Sorry I didnt see it(I have copied this solution)Now I changed to IsMouseOver but not working agaion – eoweww Oct 17 '16 at 09:26

1 Answers1

2

one thing is that you should not use IsReadOnly property in DataTrigger when MouseOver is required.

another one is that local value Visibility="Hidden" has higher priority than DataTrigger setter <Setter Property="Border.Visibility" Value="Visible" /> and will not be changed even if condition is true

a fix for both (initial value of Visibility is defined in a setter)

<Border Grid.Column="0" Background="Blue">
    <Border.Style>
        <Style>
            <Setter Property="Border.Visibility" Value="Hidden" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}" Value="False">
                    <Setter Property="Border.Visibility" Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Style>
</Border>

you should also set Grid Background to non-null value (e.g. <Grid x:Name="grid1" Background="Transparent">) for mouse movements to be registered in grid ({x:Null} vs. Transparent?)

Community
  • 1
  • 1
ASh
  • 34,632
  • 9
  • 60
  • 82
  • When I change binding to IsPressed or IsFocused in grid again.This is not working. – eoweww Oct 17 '16 at 10:22
  • `Grid.IsFocused = false` and doesn't change, that's why Border is visible. it is working but not how you expected. Grid doesn't have `IsPressed` property, how do you use it? – ASh Oct 17 '16 at 10:28