我在将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创建一个局部变量,所以我猜这是一个命名空间问题?
我将自定义控件重新编码为一个带有ContentPresenter的UserControl,并且一切正常,直到我将x:name添加到控件。 – BentOnCoding 2011-03-05 00:11:41
我收到完全相同的一组错误。 – BentOnCoding 2011-03-05 00:35:40
删除'x:Uid'它什么都不做。如果您将“模板”属性的赋值移除并使用默认模板会发生什么? – AnthonyWJones 2011-03-05 17:34:04