【发布时间】:2010-05-15 13:32:35
【问题描述】:
我的公司被困在 .Net 3.0 上。我要解决的任务很简单,我需要将 CheckBoxResolvesCEDAR 的 IsChecked 属性绑定到我的 Audio 类中的 CompletesCEDARWork。我读得越多,似乎我必须将 CompletesCEDARWork 声明为依赖属性,但我找不到一个很好的例子来说明这是如何完成的。我找到了这个例子,但是当我粘贴到我的代码中时,我得到了 GetValue 的“未定义”错误,我还没有成功地弄清楚 MyCode 应该代表什么。任何帮助/示例将不胜感激。
谢谢
Public Shared ReadOnly IsSpinningProperty As DependencyProperty = DependencyProperty.Register("IsSpinning", GetType(Boolean), GetType(MyCode))
Public Property IsSpinning() As Boolean
Get
Return CBool(GetValue(IsSpinningProperty))
End Get
Set(ByVal value As Boolean)
SetValue(IsSpinningProperty, value)
End Set
End Property
这是我现在的精简音频类。
Imports System.Xml
进口系统 导入系统.IO 导入 System.Collections.ObjectModel 导入 System.ComponentModel
公开课音频
Private mXMLString As String
Private mTarpID As Integer
Private mStartTime As Date
Private mEndTime As Date
Private mAudioArray As Byte()
Private mFileXMLInfo As IO.FileInfo
Private mFileXMLStream As IO.FileStream
Private mFileAudioInfo As IO.FileInfo
Private mDisplayText As String
Private mCompletesCEDARWork As Boolean
Private Property CompletesCEDARWork() As Boolean
Get
Return mCompletesCEDARWork
End Get
Set(ByVal value As Boolean)
mCompletesCEDARWork = value
End Set
End Property
这是我设置绑定的 XML 数据模板。
<DataTemplate x:Key="UploadLayout" DataType="Audio">
<Border BorderBrush="LightGray" CornerRadius="8" BorderThickness="1" Padding="10" Margin="0,3,0,0">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=DisplayText}">
</TextBlock>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="TARP ID" VerticalAlignment="Center"/>
<ComboBox x:Name="ListBoxTarpIDs"
ItemsSource="{Binding Path=TarpIds}"
SelectedValue="{Binding Path=TarpID}"
BorderBrush="Transparent"
Background="Transparent" >
</ComboBox>
</StackPanel>
<CheckBox x:Name="CheckBoxResolvesCEDAR"
Content="Resolves CEDAR Work"
IsChecked="{Binding ElementName=Audio,Path=CompletesCEDARWork,Mode=TwoWay}"/>
</StackPanel>
</Border>
</DataTemplate>
【问题讨论】:
标签: wpf vb.net binding dependency-properties