에서 UserControl에서 (콘텐츠) 나는 내가 다른 XAML 파일 내에서 참조/사용하고있는 다음 UserControl을 가지고 -액세스 된 ControlTemplate XAML
<UserControl x:Class="WpfApplication2.MutuallyExclusiveToggleControl"
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"
x:Name="SpecialToggleControl"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ToggleButton Content="{TemplateBinding ContentControl.Content}"
Background="{Binding ElementName=SpecialToggleControl, Path=TileBackground}"
IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}}"
Name="toggleButton"/>
<ControlTemplate.Triggers>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<ListBox x:Name="_listBox"
SelectionChanged="ListBoxSelectionChanged"
SelectedItem="{Binding ElementName=SpecialToggleControl, Path=SelectedItem}"
SelectionMode="Single" ItemsSource="{Binding ElementName=SpecialToggleControl, Path=ItemsSource}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding ElementName=SpecialToggleControl, Path=ColumnCount}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
는
는 질문 :가 어떻게 액세스합니까 ToggleButton을의를 이 UserControl을 사용하고있는 곳의 콘텐트 (ControlTemplate에 있음). 예를 들어, 콘텐츠에 따라 배경색을 설정하고 싶습니다. UserControl 내부에서이 작업을 수행하고 싶지 않습니다. 나는이 UserControl을 사용하고있는 곳에서 이것을 얻고 싶습니다.
미리 감사드립니다.
그러나 ** Content **는 ListBox의 ** ItemsSource **를 기반으로 설정됩니다 (볼 수있는 경우 e xaml). 콘텐츠를 별도로 설정하고 싶지 않습니다. –