0

안녕하세요.이 오류가 발생했습니다. Error 1 The name "TemplateSelector" does not exist in the namespace "using:MyApps"하지만 새 프로젝트를 만들고 그와 동일한 코드를 붙여 넣으면 모든 것이 작동하므로 문제는 내 이전 프로젝트에서만 발생합니다. 나는 또한 깨끗한 시도 또는 100 번 프로젝트를 다시 빌드하고 수동으로 bin 폴더를 삭제하지만 여전히 작동하지 않습니다. 프로젝트 내부이름 TemplateSelector가 네임 스페이스에 존재하지 않습니다.

<Page 
x:Class="MyApps.BlankPage1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:MyApps" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d"> 

...

<UserControl> 
      <UserControl.Resources> 
       <!-- Template for INCOMNIG messages --> 
       <DataTemplate x:Key="IncomnigTemplate"> 
        <Grid> 

         <Grid Margin="27,0,0,0" HorizontalAlignment="Left" Background="#BFE8FF" > 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="*"/> 
          </Grid.ColumnDefinitions> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="auto"></RowDefinition> 
           <RowDefinition Height="auto"></RowDefinition> 
          </Grid.RowDefinitions> 
          <TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding MessengerMessage}" HorizontalAlignment="Left" Margin="5,5,20,0" VerticalAlignment="Top" Foreground="black"></TextBlock> 
          <TextBlock Grid.Column="0" Grid.Row="1" Text="{Binding MessengerTime}" HorizontalAlignment="Left" Margin="5,0,0,5" VerticalAlignment="Bottom" FontSize="9" Foreground="#908C8C"></TextBlock> 
         </Grid> 
        </Grid> 
       </DataTemplate> 

       <!-- Template for OUTGOING messages --> 
       <DataTemplate x:Key="OutgoinTemplate"> 
        <Grid> 

         <Grid Margin="27,0,0,0" HorizontalAlignment="Right" Background="Gray" > 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="*"/> 
          </Grid.ColumnDefinitions> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="auto"></RowDefinition> 
           <RowDefinition Height="auto"></RowDefinition> 
          </Grid.RowDefinitions> 
          <TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding MessengerMessage}" HorizontalAlignment="Left" Margin="5,5,20,0" VerticalAlignment="Top" Foreground="black"></TextBlock> 
          <TextBlock Grid.Column="0" Grid.Row="1" Text="{Binding MessengerTime}" HorizontalAlignment="Left" Margin="5,0,0,5" VerticalAlignment="Bottom" FontSize="9" Foreground="#908C8C"></TextBlock> 
         </Grid> 
        </Grid> 
       </DataTemplate> 


       <!-- datatemplate selector --> 
       <local:TemplateSelector x:Key="MessageTemplateSelector" 
            EmptyTemplate="{x:Null}" 
            IncomingMessageTemplate="{StaticResource IncomnigTemplate}" 
            OutgoingMessageCaptureTemplate="{StaticResource OutgoinTemplate}"/> 


      </UserControl.Resources> 
      <ListBox ItemTemplateSelector="{StaticResource MessageTemplateSelector}" x:Name="lbChoosenMessagesUsers" Grid.Column="3" FontSize="13" ItemsSource="{Binding MyDatasCurentUser}" Margin="0,0,50,0"> 
       <ListBox.ItemContainerStyle> 
        <Style TargetType="ListBoxItem"> 
         <Setter Property="IsEnabled" Value="False"/> 
        </Style> 
       </ListBox.ItemContainerStyle> 
      </ListBox> 
     </UserControl>... 

클래스 TeplateSelector는 :

public class TemplateSelector : DataTemplateSelector 
{ 
    public DataTemplate IncomingMessageTemplate { get; set; } 
    public DataTemplate OutgoingMessageCaptureTemplate { get; set; } 
    public DataTemplate EmptyTemplate { get; set; } 

    public new DataTemplate SelectTemplate(object item, DependencyObject container) 
    { 
     var x = item as Message; 
     if (x != null) 
     { 
      return null; 
     } 

     return EmptyTemplate; 
    } 
} 
+0

'UserControl'의 XMLNS 선언을 붙여 주실 수 있습니까, 아니면 페이지가있는 중입니까? – Xyroid

+0

예 내부 페이지 xaml입니다. 그 링크 된 여기> http://stackoverflow.com/questions/18757615/listbox-with-custom-datatemplate –

+0

거기에 다른 오류가 있습니까? – Xyroid

답변

1

나는 종종 너무 같은 문제가 생겼어요. 내 솔루션은 간단합니다 : 열려있는 모든 xaml 파일을 닫은 다음 프로젝트를 다시 빌드하기 만하면됩니다. 그것은 나를 위해 작동합니다.

+0

예 깨끗한, rebulid, 모든 등을 닫습니다 내 PC를 재부 팅, 빈 폴더를 청소하지만 문제는 여전히 여기에 있습니다. 내가 말했듯이 새로운 프로젝트에서 아무 문제없이 VS 캐쉬 파일 문제처럼 보이거나 잘 모르기 때문에 코드가 좋다. –

+0

변경 public이 새 DataTemplate (개체 항목, DependencyObject 컨테이너) SelectTemplate (개체 항목, DependencyObject 컨테이너)를 재정의합니다. DataTemplate SelectTemplateCore (개체 항목, DependencyObject 컨테이너) – SimonFisher

+0

나는 그것을 얻을 수 있지만 얻습니다. 'protected'상속 된 멤버를 재정의 할 때 액세스 한정자를 변경할 수 없으므로 public으로 변경됩니다. 하지만 확실하지 그 네임 스페이스 문제가 여전히 여기에 –