Ho un UserControl con una classe ViewModel come DataContext:Binding per interno ViewModel-Proprietà
XAML
<UserControl x:Class="DotfuscatorTest.UserControl.View.UserControlView"
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" >
<StackPanel>
<TextBox Text="{Binding ViewModelProperty}"/>
</StackPanel>
</UserControl>
CodeBehind:
namespace DotfuscatorTest.UserControl.View
{
using ViewModel;
public partial class UserControlView
{
public UserControlView()
{
InitializeComponent();
DataContext = new UserControlViewModel();
}
}
}
ViewModel classe:
namespace DotfuscatorTest.UserControl.ViewModel
{
public class UserControlViewModel
{
private string viewModelProperty = "hello world";
internal string ViewModelProperty
{
get { return viewModelProperty; }
set { viewModelProperty = value; }
}
}
}
Se imposto il ViewMod elProperty to public the binding funziona bene. Ma se imposto la proprietà su internal come sopra il binding fallisce (errore di binding: property not found ...).
Ho pensato che una proprietà interna sia accessibile come pubblica nello stesso assembly. Inoltre posso accedere alla proprietà da UserControl-codebehind senza alcun problema:
{
...
((UserControlViewModel)DataContext).ViewModelProperty = "hallo viewmodel";
...
Qualsiasi explenation per questo comportamento?
Grazie in anticipo, rhe1980
Avresti dovuto uno sguardo su documenti DataBinding prima. – HichemSeeSharp