2017-07-05 13 views
0

私は5つの行のdatatemplateとリストを持っています。だから、どの列にも、コンボボックスには「はい」と「いいえ」の2つのコンボボックスがあります。したがって、ウィンドウがロードされると、ListBoxの行内のテキストボックスは、Datatemplate内でreadonly = "True"に設定されます。しかし、個々の行のコンボボックス項目から「いいえ」を選択すると、リスト内の個々の行に対してテキストボックスが編集可能になり、isReadonly = "False"になります。私のリストボックスの項目は5です。これを行う方法?combobox selecteditemで変更するテキストボックスはisReadonly

//xaml 
<ListBox x:Name="wbListDataTemplate" 
            ItemsSource="{Binding wbVisibleItems}"   
            DataContext="{DynamicResource wbItem}" 
            Background="{x:Null}" 
           SelectedItem="{Binding wbSelectedItem, Mode=TwoWay, UpdateSourceTrigger=Default}" 
           IsSynchronizedWithCurrentItem="True" Canvas.Top="33" Height="152" Width="628" LostFocus="wbListDataTemplate_LostFocus" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Initialized="wbListDataTemplate_Initialized_1"> 

          <ListBox.ItemTemplate>         
           <DataTemplate> 
            <Grid Grid.ColumnSpan="1" Grid.RowSpan="1" Height="39" Width="642" Margin="0,0,0,-14" > 
             <Grid x:Name="Grid1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="697" Margin="10,0,0,0" Height="54" > 

              <Label Margin="0,3,0,5" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2"/> 


              <ComboBox x:Name="wbselect" Margin="0,0,60,1" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Loaded="wbselect_Loaded" > 
               <ComboBoxItem x:Name="wbyes" IsSelected="True" Content="yes"></ComboBoxItem> 
               <ComboBoxItem x:Name="wbno" Content="no"></ComboBoxItem> 
              </ComboBox>           
              <TextBox x:Name="wbdepth" Text="" MaxLength="20" Margin="217,0,230,1" LostKeyboardFocus="wbdepth_LostKeyboardFocus" Grid.ColumnSpan="2" IsReadOnly="True"/>  

             </Grid> 
            </Grid> 
           </DataTemplate> 
          </ListBox.ItemTemplate>       
         </ListBox> 
+0

ストレート= YESとテーパード=いいえ? –

+0

@MightyBadaboom編集を今すぐチェックしてください –

+0

私の答えを見てください –

答えて

0

私は、この目的のためにコンボボックスを使用しないことをお勧めします(チェックボックスやトグルボタンを使用することを好む)、あなたはテキストボックススタイルでコンボボックスのSelectedIndexプロパティにDataTriggerを使用することがありますが:

<DataTemplate> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto"/> 
      <ColumnDefinition/> 
     </Grid.ColumnDefinitions> 
     <ComboBox x:Name="cb" SelectedIndex="0"> 
      <ComboBoxItem>Yes</ComboBoxItem> 
      <ComboBoxItem>No</ComboBoxItem> 
     </ComboBox> 
     <TextBox Grid.Column="1"> 
      <TextBox.Style> 
       <Style TargetType="TextBox"> 
        <Style.Triggers> 
         <DataTrigger Binding="{Binding SelectedIndex, ElementName=cb}" 
            Value="0"> 
          <Setter Property="IsReadOnly" Value="True"/> 
         </DataTrigger> 
        </Style.Triggers> 
       </Style> 
      </TextBox.Style> 
     </TextBox> 
    </Grid> 
</DataTemplate> 
0

私はこのように見えるIValueConverterを使用します。

public class ReadonlyConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     var content = ((ComboBoxItem)value).Content; 
     var isEnabled = content.Equals("yes"); 

     return isEnabled; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

そして、あなたのXAMLで

はあなたが

IsReadOnly="True" 

IsReadOnly="{Binding ElementName=wbselect, Path=SelectedItem, Converter={StaticResource ReadOnlyConverter}}" 

を変更する必要があり、あなたのコンバータへの参照を追加する必要が

<Window xmlns:converter="clr-namespace:WpfApplication1.Converters"> 
    <Window.Resources> 
     <ResourceDictionary> 
      <converter:ReadonlyConverter x:Key="ReadOnlyConverter"/> 
     </ResourceDictionary> 
    </Window.Resources> 
関連する問題