2016-07-18 9 views
0

私は、列2に特定の値が含まれているWPF Datagridを持っています。私は行1内の任意のセルをクリックし、(行1、列2)の値がtrueの場合、ユーザーコントロールがポップアップするようにしたいと思います。Datagridトリガー値に基づいたユーザーコントロール

私はこの中で巣にイベントトリガーをしようと考えていたが、私はこれを行う方法に困惑

    <DataGrid.RowStyle> 
        <Style TargetType="DataGridRow"> 
         <Style.Triggers> 
          <DataTrigger Binding="{Binding itemCtrlType}" Value="true"> 
           <Setter Property="Background" Value="Aqua"/> 
          </DataTrigger> 
         </Style.Triggers> 
        </Style> 
       </DataGrid.RowStyle> 

を使用して、行の色を変更する方法を知っています。私はこれについて間違った方法をとっていますか?

+0

...このMVPVMパターンにするためにプレゼンターを追加してみてください。発表者は、イベントを検出したときにポップアップを行います。 – Aron

答えて

1

私はあなたの質問を理解している場合、これは私のために働いています。私はあなたのブール値のプロパティが呼ばれているか分からない。私はIsOddと書いたものを書きました。

とき、これは、任意の行のポップアップを開く:行が選択され

  • 、行のDataContextPopupFalse

に等しいIsOdd特性を有し

  • DataContextは行のDataContextです。そこにXAMLを入れてください。UserControlなどです。

    本当にバグがあるのは、行プレゼンテーションXAML(SelectiveScrollingGridのすべて)です。そのようなものは答えのS/N比を損なうが、そこになければならない。少なくともあなたはそれを支配している。

    XAML:MVVMパターンがここで崩れ

    <DataGrid.RowStyle> 
        <Style TargetType="DataGridRow"> 
         <Setter Property="Template"> 
          <Setter.Value> 
           <ControlTemplate TargetType="{x:Type DataGridRow}"> 
            <Grid> 
             <!-- 
             Stole content presentation from here: 
             http://stackoverflow.com/a/14266323/424129 
             --> 
             <SelectiveScrollingGrid> 
              <SelectiveScrollingGrid.ColumnDefinitions> 
               <ColumnDefinition Width="Auto" /> 
               <ColumnDefinition Width="*" /> 
              </SelectiveScrollingGrid.ColumnDefinitions> 
              <SelectiveScrollingGrid.RowDefinitions> 
               <RowDefinition Height="*" /> 
               <RowDefinition Height="Auto" /> 
              </SelectiveScrollingGrid.RowDefinitions> 
              <DataGridCellsPresenter 
               Grid.Column="1" 
               ItemsPanel="{TemplateBinding ItemsPanel}" 
               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
               /> 
              <DataGridDetailsPresenter 
               Grid.Column="1" 
               Grid.Row="1" 
               SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" 
               Visibility="{TemplateBinding DetailsVisibility}" 
               /> 
              <DataGridRowHeader 
               Grid.RowSpan="2" 
               SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" 
               Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" 
               /> 
             </SelectiveScrollingGrid> 
             <Popup 
              x:Name="RowPopup" 
              IsOpen="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}}" 
              > 
              <Border 
               MinWidth="200" 
               MinHeight="166" 
               Background="WhiteSmoke" 
               BorderBrush="Black" 
               BorderThickness="1" 
               Padding="12" 
               > 
               <TextBlock> 
                <TextBlock Text="Blah blah popup. " /> 
                <TextBlock Text="{Binding IsOdd, StringFormat=IsOdd: {0} }" /> 
               </TextBlock> 
              </Border> 
             </Popup> 
            </Grid> 
            <ControlTemplate.Triggers> 
             <!-- 
             The RelativeSource=TemplatedParent binding doesn't seem to be working here. 
             I don't understand why not. Probably something stupid and obvious. 
             --> 
             <!-- 
             <MultiDataTrigger> 
              <MultiDataTrigger.Conditions> 
               <Condition 
                Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}}" 
                Value="True" /> 
               <Condition Binding="{Binding IsOdd}" Value="False" /> 
              </MultiDataTrigger.Conditions> 
              <Setter TargetName="RowPopup" Property="IsOpen" Value="True" /> 
             </MultiDataTrigger> 
             --> 
    
             <!-- 
             So instead, we bind IsOpen on the popup to IsSelected, and then 
             override that with False if the boolean property is true. Clumsy 
             but it works. 
             --> 
             <DataTrigger Binding="{Binding IsOdd}" Value="True"> 
              <Setter TargetName="RowPopup" Property="IsOpen" Value="False" /> 
             </DataTrigger> 
            </ControlTemplate.Triggers> 
           </ControlTemplate> 
          </Setter.Value> 
         </Setter> 
        </Style> 
    </DataGrid.RowStyle> 
    
  • 関連する問題