2013-06-19 1 views
0

У меня есть код xaml, в котором я использовал DataTemplateSelector. Но он показывает мне пространство имен error.Code позади, потому что он написан внутри пространства имен TimeSheet.Views.DataTemplate и написан код xaml в пространстве имен «TimeSheet.Views». Как мне написать пространство имен для него?Ошибка пространства имен в xaml для DataTemplateSelector

контур моего XAML код:

<Controls:MetroWindow 
    x:Name="MainWin" 
    x:Class="TimeSheet.DayView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:l="clr-namespace:TimeSheet.Views.DataTemplateSpace" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
    Title="DayView" Width="590" Height="590"> 

<l:DayViewListDataTemplateSelector x:Key="templateSelector" 
      DefaultDataTemplate="{StaticResource DefaultDataTemplate}" 
      EditableDataTemplate="{StaticResource EditableDataTemplate}"/> 

Код для За это,

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Controls; 
using System.Windows; 
//using System.Windows.DependencyProperty; 
//using System.ComponentModel.DependencyPropertyDescriptor; 
using HarvestApp; 

namespace TimeSheet.Views.DataTemplateSpace 
{ 
public class DayViewListDataTemplateSelector : DataTemplateSelector 
{ 
    public DataTemplate DefaultDataTemplate { get; set; } 
    public DataTemplate EditableDataTemplate { get; set; } 
    //public DataTemplate EnumDataTemplate { get; set; } 

    public override DataTemplate SelectTemplate(object item,DependencyObject container) 
    { 
     //some code 
    } 
} 
} 
+0

Я получил problem.There не Ошибка пространства имен на самом деле. Вам просто нужно написать ключ для ваших DataTemplates, если он находится вне mergeddictionary. – Dinesh

ответ

0

Вот ответ:

<Controls:MetroWindow 
     x:Name="MainWin" 
     x:Class="TimeSheet.DayView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:l="clr-namespace:TimeSheet.Views.DataTemplateSpace" 
     xmlns:sys="clr-namespace:System;assembly=mscorlib" 
     xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
     Title="DayView" Width="590" Height="590"> 

    <Window.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" /> 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> 
       <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 

    <DataTemplate x:Key="DefaultDataTemplate"> //here you must write key 
    <StackPanel Orientation="Horizontal"> 
    <TextBox Text="{Binding ClientNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/> 
        <TextBox Text="{Binding ApplicationNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/> 
        <TextBox Text="{Binding StartTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/> 
        <TextBox Text="{Binding StopTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/> 
        <TextBox Text="{Binding ProjectNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/> 
        <TextBox Text="{Binding TaskNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="71"/> 
       </StackPanel> 
      </DataTemplate> 

     <!-- Editable DataTemplate --> 
     <DataTemplate x:Key="EditableDataTemplate"> //here you must write key 
     <StackPanel Orientation="Horizontal"> 
       <TextBox Text="{Binding ClientNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/> 
       <TextBox Text="{Binding ApplicationNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/> 
       <TextBox Text="{Binding StartTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/> 
       <TextBox Text="{Binding StopTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/> 
       <TextBox Text="{Binding TaskNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/> 
       <ComboBox ItemsSource="{Binding projectList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedValue="{Binding selectedProjectid}" />      
      </StackPanel> 
     </DataTemplate> 

<l:DayViewListDataTemplateSelector x:Key="templateSelector" 
       DefaultDataTemplate="{StaticResource DefaultDataTemplate}" 
       EditableDataTemplate="{StaticResource EditableDataTemplate}"/> 

     </ResourceDictionary> 

    </Window.Resources>