2011-03-04 7 views
2

x : name을 사용하여 컨트롤을 사용자 지정 컨트롤에 추가하는 데 문제가 있습니다.Custom ItemsControl 하위 컨트롤 네임 스페이스 문제

x : name = "startDate"를 추가하면 모든 것이 중단됩니다. 그렇지 않으면 완벽하게 작동합니다.

ItemsControl에서 상속 한 사용자 지정 컨트롤이 있습니다. 여기

using System; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Ink; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 

namespace ControlCSI 
{ 
    public partial class SlideMenu : ItemsControl 
    { 
     public SlideMenu() 
     { 
      // Required to initialize variables 
      InitializeComponent(); 
     } 
    } 
} 

해당 클래스

<ItemsControl 
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" 
mc:Ignorable="d" 
x:Class="ControlCSI.SlideMenu" 
d:DesignWidth="200" d:DesignHeight="800"> 

<ItemsControl.ItemsPanel> 
    <ItemsPanelTemplate> 
     <StackPanel Orientation="Vertical" /> 
    </ItemsPanelTemplate> 
</ItemsControl.ItemsPanel> 

<ItemsControl.Template> 
    <ControlTemplate TargetType="ItemsControl"> 
     <Grid x:Name="LayoutRoot"> 
      <Border Height="auto" Grid.Column="0" CornerRadius="5" > 
       <Grid> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="23" /> 
         <ColumnDefinition Width="*" /> 
        </Grid.ColumnDefinitions> 
        <Border Background="Transparent"> 
         <Image Source="/ControlCSI;component/Images/GlossyBlack/bg_pulltab.png" /> 
        </Border> 
        <Grid Grid.Column="1" > 
         <Border CornerRadius="10,0,0,10" BorderBrush="#11c2f1" BorderThickness="0"> 
          <Border.Background> 
           <ImageBrush ImageSource="/ControlCSI;component/Images/GlossyBlack/bg_nav.png"/> 
          </Border.Background> 
          <ItemsPresenter /> 
         </Border> 
        </Grid> 
       </Grid> 
      </Border> 
     </Grid> 
    </ControlTemplate> 
</ItemsControl.Template>  

을의 마크 업 정의하고 여기에 구현 :

<ControlCSI:SlideMenu x:Name="SlideOutMenu" Width="200" VerticalAlignment="Stretch" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" > 
      <ControlCSI:SlideMenu.RenderTransform> 
       <CompositeTransform TranslateX="180"/> 
      </ControlCSI:SlideMenu.RenderTransform> 

      <telerik:RadButton Margin="5,10,5,0" Click="RadButton_Click" Tag="30" Content="30 Days" Style="{StaticResource SliderButton}" /> 
      <telerik:RadButton Click="RadButton_Click" Tag="60" Content="60 Days" Style="{StaticResource SliderButton}"/> 
      <telerik:RadButton Click="RadButton_Click" Tag="90" Content="3 Months" Style="{StaticResource SliderButton}"/> 
      <telerik:RadButton Click="RadButton_Click" Tag="180" Content="6 Months" Style="{StaticResource SliderButton}"/> 
      <telerik:RadDatePicker x:Name="startDate" x:Uid="startDate" DropDownOpened="startDate_DropDownOpened" DropDownClosed="startDate_DropDownClosed" DateTimeWatermarkContent="Start Date" Style="{StaticResource SliderDatePicker}" Template="{StaticResource RadDateTimePickerControlTemplate1}" /> 
      <telerik:RadDatePicker DropDownOpened="startDate_DropDownOpened" DropDownClosed="startDate_DropDownClosed" DateTimeWatermarkContent="End Date" Style="{StaticResource SliderDatePicker}" Template="{StaticResource RadDateTimePickerControlTemplate1}" /> 


     </ControlCSI:SlideMenu> 

오류 :

A first chance exception of type 'System.NullReferenceException' occurred in ControlCSI 
System.Windows.Data Error: BindingExpression path error: 'ErrorResources' property not found on 'ControlCSI.ResourceWrapper' 'ControlCSI.ResourceWrapper' (HashCode=42863040). BindingExpression: Path='ErrorResources.ErrorWindowTitle' DataItem='ControlCSI.ResourceWrapper' (HashCode=42863040); target element is 'ControlCSI.ErrorWindow' (Name=''); target property is 'Title' (type 'System.Object').. 
System.Windows.Data Error: BindingExpression path error: 'ErrorResources' property not found on 'ControlCSI.ResourceWrapper' 'ControlCSI.ResourceWrapper' (HashCode=42863040). BindingExpression: Path='ErrorResources.ErrorWindowGenericError' DataItem='ControlCSI.ResourceWrapper' (HashCode=42863040); target element is 'System.Windows.Controls.TextBlock' (Name='IntroductoryText'); target property is 'Text' (type 'System.String').. 
System.Windows.Data Error: BindingExpression path error: 'ErrorResources' property not found on 'ControlCSI.ResourceWrapper' 'ControlCSI.ResourceWrapper' (HashCode=42863040). BindingExpression: Path='ErrorResources.ErrorWindowErrorDetails' DataItem='ControlCSI.ResourceWrapper' (HashCode=42863040); target element is 'System.Windows.Controls.TextBlock' (Name='LabelText'); target property is 'Text' (type 'System.String').. 

x : name이 로컬 변수를 생성하므로 네임 스페이스 문제일까요?

+0

사용자 정의 컨트롤을 ContentPresenter가있는 UserControl로 다시 작성했으며 x : name을 컨트롤에 추가 할 때까지 모든 것이 올바르게 작동했습니다. – BentOnCoding

+0

정확한 오류 집합을 수신합니다. – BentOnCoding

+0

'x : Uid'를 제거하면 아무것도하지 않습니다. 'Template' 속성에 할당을 제거하고 기본 템플릿을 사용하면 어떻게됩니까? – AnthonyWJones

답변

0

결국 내가 어떤 문서 검토 후 권리이었다 UserControl을 (전환 : 링크의 원인을 추가

는 잘 모르겠어요 행운의

보다도 나는 연결 동작 권한을 사용 잘 했어).

컨트롤 내부에 단추와 날짜 선택 도구를 추가하고 종속성 속성에 바인딩하여 노출 시켰습니다.

0

이미 Name 속성을 제공하므로 x : Name을 해당 컨트롤에 추가 할 수 없다고 생각합니다. [이 msdn 링크]의 발언 섹션을 확인하십시오. 1

그러나 x : Name (나는 생각합니다)과 같은 방법으로 Name 속성을 사용할 수 있습니다. P http://msdn.microsoft.com/en-us/library/cc189028%28v=vs.95%29.aspx

+0

당신이 제안한 그것의 우스운 .... 나는 문자 그대로 방금 그걸 보았고 똑같은 오류를 냈습니다. \ – BentOnCoding

+0

버머 : (당신이 이것을 알아낼 수 있기를 바랍니다. –

+0

x : 이름이 특별히 처리됩니다. 정의 된'Name' 속성에'x : Name'의 값이 할당됩니다 실제로'Name' 속성이 요소에서 사용 가능할 때'Name' 또는 'x : Name'은'x : Name'을 전혀 사용하지 않습니다.'x : Name'은'Name' 속성을 가지고 있지 않더라도'FindName'과 같은 함수가 여전히 작동하기 때문에 요소에 이름을 붙일 수 있습니다. '그냥'Name'을 사용하는 것보다 더 좋습니다. – AnthonyWJones