저는 현재 기본적으로 실버 라이트 컨트롤을 확장하여 레이블과 물건을 추가하는 일반적인 컨트롤을 만들고 있습니다.하지만 바인딩을 얻는 데 어려움을 겪고 있습니다. 작업 ... 다음은 현재 작동하지 않는 사항의 예입니다커스텀 컨트롤과 바인딩에 문제가 있습니다.
UPDATE :
public class ComboboxField : Field
{
public string SelectedValuePath
{
get { return (string)this.GetValue(SelectedValuePathProperty); }
set { this.SetValue(SelectedValuePathProperty, value); }
}
public static readonly DependencyProperty SelectedValuePathProperty =
DependencyProperty.Register("SelectedValuePath", typeof(string), typeof(ComboboxField), new PropertyMetadata(string.Empty));
public string DisplayMemberPath
{
get { return (string)this.GetValue(DisplayMemberPathProperty); }
set { this.SetValue(DisplayMemberPathProperty, value); }
}
public static readonly DependencyProperty DisplayMemberPathProperty =
DependencyProperty.Register("DisplayMemberPath", typeof(string), typeof(ComboboxField), new PropertyMetadata(string.Empty, null));
public IEnumerable ItemsSource
{
get { return (IEnumerable)this.GetValue(ItemsSourceProperty); }
set { this.SetValue(ItemsSourceProperty, value); }
}
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(Object), typeof(ComboboxField), new PropertyMetadata(new List<object>()));
public object SelectedValue
{
get { return (object)GetValue(SelectedValueProperty); }
set { SetValue(SelectedValueProperty, value); }
}
public static readonly DependencyProperty SelectedValueProperty =
DependencyProperty.Register("SelectedValue", typeof(object), typeof(ComboboxField), new PropertyMetadata(null, (s, e) => { s.SetValue(Field.ValueProperty, SelectedValueProperty);}));
#region Ctors
public ComboboxField(FieldDescription fieldDescription, Form parentForm) : base(fieldDescription, parentForm)
{
this.Template = Application.Current.Resources["ComboBoxDefaultTemplate"] as ControlTemplate;
}
public ComboboxField() : base(new FieldDescription(Guid.NewGuid(), "ComboboxField1", FieldType.Collection), null)
{
this.Template = Application.Current.Resources["ComboBoxDefaultTemplate"] as ControlTemplate;
}
#endregion
}
컨트롤 템플릿 :
여기에 문제를 이해하는 데 도움이되는 몇 가지 더 상황이있다 :
<cc:ComboboxField Grid.Row="10" TitleStyle="{StaticResource labelStyle}"
Title="Countries" ItemsSource="{Binding Countries}"
SelectedValuePath="CountryId" DisplayMemberPath="CountryId"
SelectedValue="{Binding Path=SelectedCountry, Mode=TwoWay}" />
내가 잘못 여기서 뭐하는 거지 : 내가 그것을 사용하려고 해요 방법
<ControlTemplate x:Name="ComboBoxDefaultTemplate" TargetType="my:ComboboxField">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{TemplateBinding LabelColumnWidth}" />
<ColumnDefinition Width="{TemplateBinding FieldColumnWidth}" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Style="{TemplateBinding TitleStyle}" Text="{TemplateBinding Title}"></TextBlock>
<TextBlock Text="*" Grid.Row="0" Grid.Column="0" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Required, Converter={StaticResource boolToVisibility}}" Width="5" />
<TextBlock Grid.Row="1" Grid.Column="0" Style="{TemplateBinding SummaryStyle}" Text="{TemplateBinding Summary}" Grid.ColumnSpan="2"></TextBlock>
<ComboBox Style="{TemplateBinding FieldStyle}" Grid.Row="0" Grid.Column="1"
ItemsSource="{TemplateBinding ItemsSource}"
SelectedValue="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedValue, Mode=TwoWay}"
SelectedValuePath="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedValuePath, Mode=TwoWay}"
DisplayMemberPath="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DisplayMemberPath, Mode=TwoWay}"></ComboBox>
</Grid>
</ControlTemplate>
(무관 한 물건의 일부를 제거)?
NotifyPropertyChanged 호출은 중복됩니다. 기본 스타일은 키없이 Themes/Generic.xaml 파일에 배치되어야합니다. 또한 응용 프로그램을 디버깅하는 동안 출력 창을 볼 수 있으며 모든 바인딩 오류가 표시됩니다. 응용 프로그램에 바인딩 오류가 표시되면 해당 정보를 질문에 추가 할 수 있습니다. – vorrtex
@vorrtex : 필자는 항상 출력 창 팁 덕분에 제 바인딩에 문제가 있는지 파악할 수 있었는지 궁금했습니다. :) – Kassem