C# ui包裹的放射性总线指示器内的元件';的内容为空
我有一个有趣的用户界面问题。我从Telerik那里得到了一个C# ui包裹的放射性总线指示器内的元件';的内容为空,c#,silverlight,xaml,telerik,C#,Silverlight,Xaml,Telerik,我有一个有趣的用户界面问题。我从Telerik那里得到了一个RadBusyIndicator,它被包装在一个用户控件中(如果Telerik one仍然存在内存泄漏,则可以轻松切换到Windows忙指示灯)。当我将内容放入控件时,如果包装器控件的开始标记和结束标记之间的内容超过了ContentControl,则所有带有x:Name属性的内容在后面的代码中都为null,并在加载页面时导致异常 这是一个代码的相似之处,删除了名称以保护无辜者 xaml <UserControl> &
RadBusyIndicator
,它被包装在一个用户控件中(如果Telerik one仍然存在内存泄漏,则可以轻松切换到Windows忙指示灯)。当我将内容放入控件时,如果包装器控件的开始标记和结束标记之间的内容超过了ContentControl
,则所有带有x:Name
属性的内容在后面的代码中都为null,并在加载页面时导致异常
这是一个代码的相似之处,删除了名称以保护无辜者
xaml
<UserControl>
<Grid x:Name="Indicator">
<telerik:RadBusyIndicator x:Name="BusyIndicator" IsBusy="{Binding Path=IsStatusBusy, Mode=TwoWay}" BusyContent="{Binding Path=WaitingContent, Mode=TwoWay}" Content="{Binding Path=UserContent, Mode=TwoWay}"/>
</Grid>
</UserControl>
而我就是这样用的
<CustomBusyIndicator IsStatus={Binding IsBusy}>
<CustomBusyIndicator.WaitingContent>
<TextBlock Text="Loading..." Foreground="Black" />
</CustomBusyIndicator.WaitingContent>
<Grid>
.
.
.
.
</Grid>
</CustomBusyIndicator>
.
.
.
.
有什么想法吗?提前感谢您的帮助
编辑
我现在已经确定是x:名称引起了这些问题。调用
InitializeComponent()
后,它们在代码隐藏中为空。您从UserControl
派生,那么会发生什么。。。让我们看看:
您的类继承了一个名为Content
的公共属性,而该属性正是基类的专用ContentProperty
,由基类级别的[ContentProperty(“Content”)]
之类的注释引起的
这就是为什么用户控件定义的xaml部分中声明的所有内容在加载时正常显示的原因。
所以当你看到这个
<UserControl ... >
<Grid x:Name="Indicator">
<telerik:RadBusyIndicator x:Name="BusyIndicator" ... />
</Grid>
</UserControl>
选项2:从控件
或内容控件
派生,并将用户控件的xaml部分转换为默认控件模板
这样你就可以像这样使用它
<CustomBusyIndicator ...>
<Grid> ... </Grid>
</CustomBusyIndicator>
据我所知,这与
x:Name
无关。等一下,我会在答案部分写下一个正确的答案。我会查出来的。谢谢你的回答。我花了一段时间才完全理解你说的话,但你的第二种方法在金钱上是正确的。多谢各位@Madvilla:我考虑过我的陈述“如果你想使用ContentProperty快捷语法,就不能使用UserControl”,这是不对的。您应该能够在定义中显式地设置xaml部分,但我还没有尝试过。我把它作为第三个选项添加到我的答案中。
<UserControl ... >
<UserControl.Content>
<Grid x:Name="Indicator">
<telerik:RadBusyIndicator x:Name="BusyIndicator" ... />
</Grid>
</UserControl.Content>
</UserControl>
<CustomBusyIndicator ...>
<Grid> ... </Grid>
</CustomBusyIndicator>
<CustomBusyIndicator ...>
<CustomBusyIndicator.UserContent>
<Grid> ... </Grid>
</CustomBusyIndicator.UserContent>
</CustomBusyIndicator>
<CustomBusyIndicator ...>
<Grid> ... </Grid>
</CustomBusyIndicator>
<UserControl ... >
<UserControl.Content>
<Grid x:Name="Indicator">
<telerik:RadBusyIndicator x:Name="BusyIndicator" ... />
</Grid>
</UserControl.Content>
</UserControl>