2017-10-10 17 views
0

의 내가 그것을 GRIDVIEW의 유일한 컬럼의 단일 버튼으로 간단하게 ListView에 있다고 가정 해 봅시다 :취급 버튼의 클릭 명령 내부의 ListView

<ListView x:Name="SomeListView" ItemsSource="{Binding Whatever}"> 
    <ListView.View> 
     <GridView> 
      <GridViewColumn CellTemplate="{StaticResource myCellTemplate}" Header="ColumnHeader"/> 
     </GridView> 
    </ListView.View> 
</ListView> 

그리고 myCellTemplate은 다음과 같습니다 myClickCommand ICommand의로

<DataTemplate x:Key="myCellTemplate"> 
    <Viewbox> 
     <Button x:Name="mybutton" Command="{Binding myClickCommand}" Content="{Binding btnBinding}"></Button> 
    </Viewbox> 
</DataTemplate> 

을 내 VM에서. 이 시점에서 모든 것은 늠름한 이야기이며 사용자가 내 버튼을 클릭하면 myClickCommand가 호출됩니다. 지금, 나는 나의 행에 대한 몇 가지 마우스 오버 스타일을 추가 할, 그래서이 같은 ItemContainerStyle을 추가

<ListView x:Name="SomeListView" ItemContainerStyle="{StaticResource myItemStyle}" ItemsSource="{Binding Whatever}"> 
    ... 
</ListView> 

myItemStyle와 같이

<Style x:Key="myItemStyle" TargetType="{x:Type ListViewItem}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListViewItem}"> 
       <Grid> 
        <Border x:Name="borderMain" BorderThickness="1" BorderBrush="Transparent"> 
         <GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
        </Border> 
        <Rectangle x:Name="rectGlass" Fill="LightGray" Opacity=".2" Visibility="Hidden"></Rectangle> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Setter TargetName="borderMain" Property="BorderBrush" Value="DarkGray" /> 
         <Setter TargetName="rectGlass" Property="Visibility" Value="Visible"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

이 시점에서, 사용자의 클릭하지 않습니다 아마도 이벤트가 버튼으로 라우팅되지 않았기 때문에 myClickCommand를 트리거하십시오. 이것을 달성 할 수있는 방법이 있습니까?

답변

0

직사각형 (직사각형)이 버튼 위에 있습니다. 클릭 이벤트가 실제로 클릭되지 않기 때문에 버튼에 클릭 이벤트가 수신되지 않습니다.

+0

흠. 좋아, rectangle 사각형의 "위에"테두리를 배치하려면 myItemStyle의 컨트롤 순서를 변경할 수 있습니다. 이 버튼을 클릭 수 있지만 stylistically 내가 무슨 일이 있었는지 꽤되지 않습니다. 어쨌든, 이것은 질문에 답합니다. 고맙습니다. – sabelbe