我已经为灯光开关创建了以下自定义控件,我如何访问和获取数据?
<UserControl x:Class="CustomControls.DateRange"
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"
d:DesignHeight="75" d:DesignWidth="123">
<Grid x:Name="LayoutRoot" Background="White" Height="73">
<ComboBox Height="23" HorizontalAlignment="Left" Margin="12,9,0,0" Name="cmbStartYear" VerticalAlignment="Top" Width="100" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="13,39,0,0" Name="cmbStartMonth" VerticalAlignment="Top" Width="99" />
</Grid>
</UserControl>
xaml.vb 文件编码:在这里,我根据我的逻辑为这些组合框添加了值。
Private Sub UserControl_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Dim availableYears As List(Of Integer) = GetYears()
For Each year As Integer In availableYears
cmbStartYear.Items.Add(year)
Next
End Sub
然后我将该自定义控件添加到屏幕。(首先创建属性,然后为其分配自定义控件)
运行时会显示如下
所以我的问题是如何访问这两个组合框并获得它的价值?
我找到
Dim cmbyear As IContentItemProxy = Me.FindControl("StartYear")
可用于访问控制。但是我怎样才能分别获得每个控件的值?