사용자 컨트롤이 flipview 내부에있는 Windows Store 앱에서 작업하고 있습니다.사용자 정의 컨트롤 내에서 바인딩 속성이 변경되었습니다.
사용자 제어 : (ImagePage.xaml)
<UserControl
x:Name="userControl"
x:Class="MWC_online.Classes.ImagePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MWC_online.Classes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="768"
d:DesignWidth="1366">
<Grid Background="#FFF0F0F0" Margin="4,0">
...
<Image Source="{Binding Img}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" />
<StackPanel x:Name="stackPanel" HorizontalAlignment="Left" Margin="984,83,0,0" Width="325">
<Grid Background="{Binding Colour}">
<TextBlock Margin="30,30,30,15" Text="{Binding TextContent1}" FontWeight="Light" TextWrapping="Wrap" Foreground="#FF00ABE8" FontSize="29" />
</Grid>
<Grid Background="{Binding Colour}">
<TextBlock Margin="30,10,30,30" Text="{Binding TextContent2}" TextWrapping="Wrap" Foreground="#FF606060" FontSize="17" />
</Grid>
</StackPanel>
</Grid>
</UserControl>
사용자 컨트롤 클래스 : (ImagePage.xaml.cs) 모두가 OnTextContent1Changed를 제외하고 잘 작동
private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e){
StackPanel stackPanel = (StackPanel)d;
stackPanel.Visibility = Visibility.Collapsed;
}
public string TextContent1
{
get { return (string)GetValue(TextContent1Property); }
set { SetValue(TextContent1Property, value); }
}
public static readonly DependencyProperty TextContent1Property =
DependencyProperty.Register("TextContent1", typeof(string), typeof(ImagePage), new PropertyMetadata("", new PropertyChangedCallback(OnTextContent1Changed)));
private static void OnTextContent1Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// what I want to do is if TextContent1 or TextContent2 has no value
// turn the stackpanel visibility to collapsed
StackPanel stackPanel = (StackPanel)d;
stackPanel.Visibility = Visibility.Collapsed;
}
은 아니다 발사! 그래서 이것이 일을하는 올바른 방법인지는 모르겠지만 기본적으로 사용자 정의 컨트롤 내 UI 요소는 데이터 바인딩에 따라 ON 또는 OFF로 전환하려고합니다.
감사합니다. @ Thanatos, 죄송 합니다만, 문제가 있을지 모르겠지만 UI 요소를 잘 처리 할 수 있습니다 (내 전체 이미지 페이지 클래스를 표시하지 않았지만 사실 DataContext를 선언했습니다. 거기에)하지만 내가 가진 문제는 'OnTextContent1Changed'는 페이지가 렌더링되고 바인딩 데이터가 입력 될 때 절대 호출되지 않는다. 내 'OnTextContent1Changed'메소드에서 Debug.WriteLine을 가졌지 만 결코 호출되지 않았다. –
바인딩 데이터를 입력하기 전이나 후에 DataContext를 설정합니까? 그리고 페이지가 렌더링 된 후 어느 시점에서 속성을 변경해야한다면 'OnTextContent1Changed'가 호출됩니까? 또한 TextContent1의 get/set 블록에 breakpoint 또는 Debug 문을 넣고 올바르게 트리거하는지 확인합니다. – Thanatos
고마워요 @ Thanatos, 끝 부분에서 이름이 지정된 textblocks의 값이 비어 있거나 onLoaded에 없는지 확인하여 구조를 약간 변경했습니다. 이전에 생각할 수없는 쉬운 수정이었습니다. 너무 길어 보였습니다. 텍스트 블록 바인딩에 대한 아이디어 –