DependencyProperty綁定問(wèn)題我創(chuàng)建了一個(gè)小文件瀏覽器控件:<UserControl x:Class="Test.UserControls.FileBrowserControl"
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="44" d:DesignWidth="461" Name="Control">
<Grid Margin="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Margin="3" Text="{Binding SelectedFile}" IsReadOnly="True" TextWrapping="Wrap" />
<Button HorizontalAlignment="Right" Margin="3" Width="100" Content="Browse" Grid.Column="1" Command="{Binding BrowseCommand}" />
</Grid></UserControl>我就是這樣用的:<userControls:FileBrowserControl SelectedFile="{Binding SelectedFile}" Filter="XSLT File (*.xsl)|*.xsl|All Files (*.*)|*.*"/>(SelectedFile是使用此控件的用戶控件的ViewModel的屬性)當(dāng)前的問(wèn)題是,當(dāng)我單擊Browse時(shí),user控件中的TextBox正在正確更新,但viewModel父控件的SelectedFile屬性沒有設(shè)置(沒有調(diào)用set屬性)。如果我將綁定模式設(shè)置為twoway,則會(huì)得到以下異常:An unhandled exception of type 'System.StackOverflowException' occurred in Unknown Module.那我做錯(cuò)什么了?
DependencyProperty綁定問(wèn)題
慕尼黑的夜晚無(wú)繁華
2019-06-29 11:16:01