我有这个代码:
namespace Test
{
public partial class SearchField : UserControl
{
public SearchStrategy Strategy { get; set; }
public SearchField() { InitializeComponent(); }
}
public class TextToTipConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
SearchStrategy Strategy = // How do I get reference to SearchField.Strategy from here?
return Strategy.parseInput<string> (value.ToString(), (first, inp) => Strategy.tipMap.ContainsKey(first) && inp.Length == 1 ? first + Strategy.tipMap[first] : "", AppResources.GeneralSearchTip);
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
XAML 中的代码:
<UserControl.Resources>
<controls:TextToTipConverter x:Key="TextToTip" />
</UserControl.Resources>
...
<TextBox x:Name="Search" Grid.Column="0" Canvas.ZIndex="1"
Style="{StaticResource SearchBoxStyle}" Foreground="{StaticResource PhoneForegroundBrush}" />
<TextBox x:Name="Tip" Grid.Column="0" Canvas.ZIndex="0" IsReadOnly="True"
Style="{StaticResource SearchBoxStyle}" Opacity="0.5" Foreground="{StaticResource PhoneAccentBrush}"
Text="{Binding ElementName=Search, Converter={StaticResource TextToTip}, Path=Text}" />
SearchField
'sSearchStrategy Strategy
有一些我需要从中访问的方法和字段TextToTipConverter
。我怎样才能得到它?