현재 WPF에 대해 조금 배우고 있지만 DataBindings를 이해하지 못하고 있습니다. StackOverflow 및 MSDN에서 찾은 많은 솔루션을 시도했지만 아무도 내가 원하는 것을 수행하지 않습니다.데이터 자체 제작 클래스의 속성에 바인딩
C# -Class :
나는 다음과 같은 구조를 가지고
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestDataBindings
{
internal class TextStore
{
internal ObservableCollection<string> Collection { get; set; }
internal string Text { get; set; }
internal TextStore()
{
this.Text = "Hello World!!!!";
this.Collection = new ObservableCollection<string> { "hello", "World", "!!!!" };
}
}
}
XAML :
<Window x:Class="TestDataBindings.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestDataBindings"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:TextStore x:Key="TextStorage"></local:TextStore>
</Window.Resources>
<Grid>
<TextBox HorizontalAlignment="Left" Height="23" Margin="160,108,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Text="{Binding Source={StaticResource TextStorage}, Path=Text}"/>
<ListBox HorizontalAlignment="Left" Height="100" Margin="305,73,0,0" VerticalAlignment="Top" Width="100" ItemsSource="{Binding Source={StaticResource TextStorage}, Path=Collection}"/>
</Grid>
</Window>
지금은 안녕하세요을 기대 !!!! 내 TextBox와 내 ListBox에 팝하는 세 개의 문자열 안에 나타나지만 그 중 어떤 것도 일어나지 않습니다. 아무도 내가 여기서 뭘 잘못하고 있다고 말할 수 있습니까?
에만 공용 속성에 바인딩 할 수 있습니다. 내부에서 공개로 변경해보십시오. 클래스와 생성자는 여전히 내부 일 수 있습니다. – ShyKnee
대단히 감사합니다. 한 번에 많은 문제를 해결했습니다. 공공재에만 바인딩 할 수 있다고 알려주는 문서가 있습니까? 나는 힌트를 찾기 위해 많은 자습서를 읽었지 만, 당신은 공공 재산에 묶을 수 없다는 것을 결코 발견하지 못했습니다. 정말 고마워요. –
[Heres some] (http://msdn.microsoft.com/en-us/library/ms743643%28v=vs.110%29.aspx#binding_sources). 또한 출력 창은 일반적으로 문제를 추적하는 데 도움이됩니다. 그것은 나에게 많은 시간을 절약 해주었습니다. – ShyKnee