何我在WPF用户自定义控件中修改控件的属性? [英] Ho do I modify the property of a control in WPF user custom control?
本文介绍了何我在WPF用户自定义控件中修改控件的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试编写一个WPF用户控件(输出是一个DLL),这是其他WPF控件的集合。
我添加到项目我需要的控件,我想在我的用户控件中公开它们的一些属性,但我注意到我无法调用它们!
Imports System.Windows.Media
Imports System.Windows.Media.Media3D
Imports HelixToolkit.Wpf
Imports System.Windows.Media.Drawing
公开 类 viewer
公共 属性 BackColor 作为颜色
获取
返回 Canvas1.Background ' < - 这不起作用,Canvas1无法访问!
结束 获取
设置( ByVal 颜色作为颜色)
Canvas1.removed = color ' < ; - 这不起作用,Canvas1无法访问!
结束 设置
结束 属性
结束 班级
请帮忙!我无法理解该怎么做,我没有找到任何例子!
谢谢,
Giovanni
解决方案
查看器是用户控件/窗口的代码吗?如果不是,那么你不能在这样的控件上设置属性,因为它实际上并不是该视图的一部分。
修改后显示通话to InitializeComponent()Imports System.Windows.Media
Imports System.Windows.Media.Media3D
Imports HelixToolkit.Wpf
Imports System .Windows.Media.Drawing
公共 类 viewer
< span class =code-keyword>公开 Sub 新()
InitializeComponent()
结束 Sub
公共 属性 BackColor() As 颜色
获取
返回 Canvas1.Background
结束 < span class =code-keyword>获取
设置
Canvas1.removed = value
结束 设置
结束 属性
结束 类块引用>
解决了! XAML代码的第一行必须报告类的名称:
< usercontrol x:class =viewerxmlns:x =#unknown> ;
xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x =http://schemas.microsoft .com / winfx / 2006 / xaml
xmlns:mc =http://schemas.openxmlformats.org/markup-compatibility/2006
xmlns:d = http://schemas.microsoft.com/expression/blend/2008
mc:Ignorable =d
d:DesignHeight =300d:DesignWidth = 300xmlns:h =http://helixtoolkit.codeplex.com>
< grid>
...
然后所有控件都可以访问!
Hi all,
I'm trying to write a WPF user control (output is a DLL) which is an assemblage of other WPF controls.
I added to the project the controls I need and I want to expose some of their properties in my user control, but I noticed that I cannot call them!
Imports System.Windows.Media Imports System.Windows.Media.Media3D Imports HelixToolkit.Wpf Imports System.Windows.Media.Drawing Public Class viewer Public Property BackColor As Color Get Return Canvas1.Background ' <- this does not work, Canvas1 not accessible! End Get Set(ByVal color As Color) Canvas1.removed=color ' <- this does not work, Canvas1 not accessible! End Set End Property End Class
Please help! I cannot inderstand what to do and I didn't find any example!
Thanks,
Giovanni解决方案Is viewer the code behind for your user control/window? If it's not, then you can't set a property on a control like this because it's not actually part of that view.
[Edit]Amended to show the call to InitializeComponent()Imports System.Windows.Media Imports System.Windows.Media.Media3D Imports HelixToolkit.Wpf Imports System.Windows.Media.Drawing Public Class viewer Public Sub New() InitializeComponent() End Sub Public Property BackColor() As Color Get Return Canvas1.Background End Get Set Canvas1.removed = value End Set End Property End Class
Solved! the first row of the XAML code must report the name of the class:
<usercontrol x:class="viewer" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" xmlns:h="http://helixtoolkit.codeplex.com">
<grid>
...
and then all the controls will be accessible!
这篇关于何我在WPF用户自定义控件中修改控件的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文