[英]Access controls not properties in XAML User Control
我已經知道如何編寫用戶控件以及如何使用XAML用戶控件中的依賴項屬性訪問內部控件屬性。
我的問題是,如何在用戶控件內部訪問控件本身。 例如,
用戶控件:TbCanvas.xaml
<UserControl
x:Class="Sample.Control.TbCanvas"
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"
d:DesignHeight="300"
d:DesignWidth="400"
x:Name="root">
<Grid>
<Image x:Name="imageMain" />
</Grid>
</UserControl>
我想在具有如下用戶控件的某些Page
中使用它。
SomePage.xaml.cs
this.tbCanvas.imageMain.Source = "some_path";
當然,可以將Source
作為具有Binding
Dependency Property
給出,但是我有時需要訪問內部控件,因為控件的每個屬性都不是完全可綁定的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.