2014-01-08 9 views
0

메인 창메인 윈도우의 텍스트 상자에서 UserControl을 텍스트 상자

<TextBox x:Name="fbSearchBox" Margin="69,10,298,11" TextWrapping="Wrap" BorderBrush=" x:Null}"/> 
<local:FacebookAutoComplete "want to set text from here of fbSearchBox" /> 

사용자 컨트롤 내부 바인딩 텍스트 WPF

<UserControl x:Class="ZuneWithCtrls.Pages.Facebook.Home.FacebookAutoComplete" 
     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" 
     d:DesignHeight="300" d:DesignWidth="300" Width="431" Height="49" 
     x:Name="uc"> 
<TextBlock x:Name="txtDynamicText"/> 

</UserControl> 

는 fbSearchBox에서 유형 .. Plz은 도움이 때 txtdynamicText에 텍스트를 표시 할

답변

4

바인딩 할 수있는 사용자 정의 컨트롤에서 일부 속성이 필요합니다.
사용자 컨트롤에 종속성 속성을 추가

public static readonly DependencyProperty DynamicTextProperty = 
     DependencyProperty.Register(
      "DynamicText", 
      typeof(string), 
      typeof(FacebookAutoComplete), 
      new FrameworkPropertyMetadata(null)); 

    public string DynamicText 
    { 
     get { return (string)GetValue(DynamicTextProperty); } 
     set { SetValue(DynamicTextProperty, value); } 
    } 

바인딩이 종속성 속성에 대한 사용자 컨트롤 내부에 중첩 된 제어 : 이제

<TextBlock x:Name="txtDynamicText" 
      Text="{Binding Path=DynamicText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"/> 

당신이 MainWindow에서 TextBoxFacebookAutoComplete.DynamicText을 결합 할 수 있습니다 :

<local:FacebookAutoComplete DynamicText="{Binding Text, ElementName=fbSearchBox, UpdateSourceTrigger=PropertyChanged}"/> 
+0

데니스에게 감사드립니다. –

관련 문제