2015-01-13 76 views
0

我正在通过模板控件创建我的第一个自定义控件。现在,它工作得很好,但我不知道如何在我的表中获取的SelectedItem:XAML模板控制如何编写类似SelectedItem的东西

<Style TargetType="local:DiaryControl"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="local:DiaryControl"> 
       <Border 
        Background="{TemplateBinding Background}" 
        BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}"> 
        <ListBox ItemsSource="{Binding Path=Students, RelativeSource={RelativeSource TemplatedParent}}"> 
         <ListBox.ItemTemplate> 
          <DataTemplate> 
           <Grid Width="Auto" HorizontalAlignment="Stretch"> 
            <Grid.ColumnDefinitions> 
             <ColumnDefinition Width="*"/> 
             <ColumnDefinition Width="*"/> 
             <ColumnDefinition Width="*"/> 
             <ColumnDefinition Width="*"/> 
             <ColumnDefinition Width="*"/> 
             <ColumnDefinition Width="*"/> 
            </Grid.ColumnDefinitions> 

            <Grid Column="0" Margin="20,0,10,0"> 
             <TextBlock VerticalAlignment="Center" Text="{Binding Id}"/> 
            </Grid> 
            <Grid Column="1" Margin="0,0,20,0"> 
             <TextBlock VerticalAlignment="Center" Text="{Binding FullName}"/> 
            </Grid> 
            <Grid Column="2" Margin="0,0,20,0"> 
             <ComboBox VerticalAlignment="Center" Height="20" FontSize="18" SelectedIndex="{Binding Reason, Mode=TwoWay}"> 
              <ComboBoxItem Content="1"/> 
              <ComboBoxItem Content="2"/> 
              <ComboBoxItem Content="3"/> 
             </ComboBox> 
            </Grid> 
            ... 
            <Grid Column="5" Margin="0,0,20,0"> 
             <Button VerticalAlignment="Center" Content="{Binding Comment}"/> 
            </Grid> 
           </Grid> 
          </DataTemplate> 
         </ListBox.ItemTemplate> 
        </ListBox> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

例如,当我触摸文本框,TextBlock的等在生成的表,我想在控制类似的SelectedItem,用选定的对象做一个动作。

谁能帮忙?我可以在哪里了解它?

回答

0

首先我需要从ICommand的学生集合添加到班级学生

public ICommand Process 
{ 
    get 
    { 
     return new RelayCommand<object>((arg) => 
     { 
      Student button = arg as Student; 
      ----do something 
     } 
    }); 
} 

和XAML:命令= “{绑定过程}”,CommandParameter = “{结合}”

相关问题