2016-05-17 4 views
0

を使用して、ええとこれは私の実装であるユーザコントローラTextChangedイベントではない私は、検索ユーザーのコントローラを作成したユーザーコントロール

<UserControl x:Class="VSOft.WpfControls.VSeachTextBox.VSearchTextBox" 
     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" 
     xmlns:local="clr-namespace:VSOft.WpfControls.VSeachTextBox" 
     xmlns:resx="clr-namespace:VSOft.WpfControls.Properties" 
     xmlns:VFontAwsome="clr-namespace:VSOft.WpfControls.VFontAwsome" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300" Height="25" MouseLeftButtonDown="UserControl_MouseLeftButtonDown"> 
<Viewbox> 
    <Grid> 
     <TextBox 
      x:Name="SearchText" 
      Margin="0" 
      TextWrapping="Wrap" 
      Text="" Height="25" 
      GotFocus="SearchText_GotFocus" 
      TextInput="SearchText_TextInput" 
      TextChanged="SearchText_TextChanged" /> 
     <Label x:Name="SearchHelperLabel" Content="Search" Height="25" Foreground="#FF9E9292" GotFocus="SearchHelperLabel_GotFocus" /> 
     <TextBlock x:Name="SearchTextIcon" TextWrapping="Wrap" Margin="275,0,0,0" Height="25" Foreground="{x:Null}" GotFocus="SearchTextIcon_GotFocus" HorizontalAlignment="Right"> 
     <VFontAwsome:VFontAwsome VForeground="{DynamicResource SideBar.Icon.Normal}" VFontSize="20" VFontsType="search" Height="25" Width="25" HorizontalAlignment="Right" /> 
     </TextBlock> 
    </Grid> 
</Viewbox> 

を使用したとき、私はTextChangedイベントを利用できるように文句を言わないとき。ユーザーコントロールを使用しているときにTextchangedイベントを使用可能にする方法これを行うには

+1

あなたのイベントは解雇されないか、mainwindowから電話したいですか? – Rohit

+0

こんにちはカイルそれが起動している私はメインウィンドウからそれを呼び出したい。ありがとうございました – Kalanamith

+1

mainwindowで関数に異なる実装を追加したいのですか、既存のものを使用しますか?もし既存のものを使用したいのであれば、そのオブジェクトを作成し、そのプロパティにアクセスすることによってusercontrolイベントを直接呼び出すことができます。 'myUsercontrol.SearchText_GotFocus(this、null)' – Rohit

答えて

1

一つの方法は、あなたのユーザーコントロールにデリゲートを配置し、あなたのUserControl.xaml.cs

public event RoutedEventHandler TestClick; 

    void onSearchFocus(object sender, RoutedEventArgs e) 
    { 
     if (this.TestClick != null) 
     { 
      this.TestClick(this, e); 
     } 
    } 

とXAMLではメインウィンドウに

にそれにアクセスRoutedEvent Handler delegateを使用することです

<Grid> 
     <TextBox 
     x:Name="SearchText" 
     Margin="0" 
     TextWrapping="Wrap" 
     Text="" Height="25" 
     GotFocus="onSearchFocus" 

他のコマンドと同じように、メインウィンドウのTestClick代理人にアクセスして、ナビゲーションハンドラを作成することができます。

<Grid> 
     <my:UserControl x:Name="testcontrol" TestClick="mycommand_click" /> 
    </Grid> 
関連する問題