gpt4 book ai didi

c# - 自定义 ItemsControl 子控件命名空间问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:47:58 25 4
gpt4 key购买 nike

我在将带有 x:name 的控件添加到我的自定义控件时遇到问题。

添加 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 创建了一个局部变量,所以我猜这是一个命名空间问题?

最佳答案

我认为您不能将 x:Name 添加到该控件,因为它已经提供了 Name 属性。查看 [此 msdn 链接] 的备注部分。 1

但是,您可以像使用 x:Name 一样使用该 Name 属性(我认为)。

祝你好运

添加链接是因为我不确定我是否正确使用了链接行为 :P http://msdn.microsoft.com/en-us/library/cc189028%28v=vs.95%29.aspx

关于c# - 自定义 ItemsControl 子控件命名空间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5200354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com