1
我已經爲lightswitch創建了以下自定義控件,並且如何訪問和獲取數據?如何訪問lightswitch中的自定義控件值
<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")
可以被用於訪問控制。但我怎麼能分別得到每個控制的價值?