2012-07-11 55 views
0

我如何可以將屬性Namex:Name添加到這個XAML代碼(組合框):活動添加到XAML

<DataGridTemplateColumn Header="Status"> 
    <DataGridTemplateColumn.CellTemplate> 
     <DataTemplate> 
      <TextBlock VerticalAlignment="Center" Text="{Binding name_ru}" Width="Auto" /> 
     </DataTemplate> 
    </DataGridTemplateColumn.CellTemplate> 
    <DataGridTemplateColumn.CellEditingTemplate> 
     <DataTemplate> 
      <ComboBox Style="{DynamicResource ComboBoxStyle}" SelectionChanged="status_SelectionChanged" Height="auto" Width="Auto"> 
       <ComboBox.BorderBrush> 
        <SolidColorBrush Color="{DynamicResource Color1}"/> 
       </ComboBox.BorderBrush> 
      </ComboBox> 
     </DataTemplate> 
    </DataGridTemplateColumn.CellEditingTemplate> 
</DataGridTemplateColumn> 

以及如何添加事件Click或其他在此XAML代碼:

<!--Clien--> 
<DataGridTemplateColumn Header="Client name" HeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}"> 
    <DataGridTemplateColumn.CellTemplate> 
     <DataTemplate> 
      <TextBlock VerticalAlignment="Center" Text="{Binding user_name}" Width="Auto" Height="Auto" /> 
     </DataTemplate> 
    </DataGridTemplateColumn.CellTemplate> 
</DataGridTemplateColumn> 
<!--end Clien--> 

我的頂尖xaml:

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic" 
     xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
     xmlns:ee="http://schemas.microsoft.com/expression/2010/effects" 
     xmlns:System="clr-namespace:System;assembly=mscorlib" 
      mc:Ignorable="d" 
    x:Class="JanPizza.IndexFormPizza" 
    x:Name="MainWnd" 
    Title="MainWindow" 
    MouseLeftButtonDown="MainWnd_MouseLeftButtonDown" 
    ResizeMode="CanResizeWithGrip" 
    xmlns:wpftoolkit="http://schemas.microsoft.com/wpf/2008/toolkit" 
    xmlns:filter="clr-namespace:DataGridFilterLibrary;assembly=DataGridFilterLibrary"  

    Width="1065" Height="674" Background="{x:Null}" BorderThickness="0" Margin="5" WindowStartupLocation="CenterScreen" Foreground="#FF2D2D2D" Icon="wnd-icon.png" Style="{DynamicResource WindowStyle}" AllowsTransparency="True" WindowStyle="None" AllowDrop="False"> 
+0

這是什麼問題? '<組合框名稱=「狀態」....' – harry180 2012-07-11 07:41:11

+0

代碼 – kekus 2012-07-11 07:42:53

+0

不可行你試過了什麼? – harry180 2012-07-11 07:43:43

回答

0

只需使用屬性:

<ComboBox Name="myCombobox" ... /> <TextBlock MouseLeftButtonDown="textblock_mouseLeftButtonDown" ... /> 
+0

數據網格中的組合框,yow答案是錯誤的 – kekus 2012-07-11 08:06:09

+0

這沒有錯,您可以添加一個名稱,只是您將無法引用它,因爲它位於模板中。 – laszlokiss88 2012-07-11 08:22:53

+0

如果我設置了名稱,那麼這裏在代碼中不可見,我需要在代碼中可見 – kekus 2012-07-11 08:27:06