2015-02-24 5 views
0

Недавно я начал работать с Silverlight 5. Мне нужно реализовать возможность необязательного скрытия подсказок для всех элементов управления, которые присутствуют на странице.Скрыть всплывающую подсказку для всех элементов управления страницами Silverlight

Например, страница содержит группу кнопок:

<Button Command="{Binding Path=VerifyDocCommand}" ToolTipService.ToolTip="{Binding Source={StaticResource Trans}, Path=ToolTipSaveButton}" CommandParameter="{Binding Path=Documents.CurrentItem, FallbackValue=null}" Style="{StaticResource VerifyButton}"/> 
... 

я создаю следующий стиль для ToolTip:

<navigation:Page.Resources> 
    <Style TargetType="ToolTip"> 
     <Setter Property="Visibility" Value="{Binding ShowTooltips, Converter={StaticResource BoolToVisibilityConv}}"/> 
    </Style> 
</navigation:Page.Resources> 

Но подсказка кнопки выше еще видна, даже если я используйте этот стиль:

<navigation:Page.Resources> 
    <Style TargetType="ToolTip"> 
     <Setter Property="Visibility" Value="Collapsed"/> 
    </Style> 
</navigation:Page.Resources> 

Не могли бы вы посоветовать, как я могу реализовать эта функциональность?

+0

try set tooltip property = ""? –

+0

try set tooltip property ToolTipService.IsEnabled = "False"? –

ответ

1

Я не могу найти удобный способ, который предлагает Silverlight ToolTipService.

я могу думать о двух возможных решений:

Первое решение: Ввести правила кодирования для вашего проекта, который в основном говорит:

все ToolTip Bindings должны либо использовать SwitchOffConverter (если их источник является DataContext) или иметь SwitchOffTextResources объект в качестве источника

и использовать следующим образом:

<Button 
    Command="{Binding VerifyDocument}" 
    ToolTipService.ToolTip="{Binding Path=LocalizedText.VerifyDocument_ToolTip, 
     Source={StaticResource DeactivatableUiText}}"/> 

или

<Button 
    Command="{Binding VerifyDocument}" 
    ToolTipService.ToolTip="{Binding Path=VerifyDocument.Description, 
     Converter={StaticResource ToolTipSwitcher}}"/> 

с

<Resources> 
    <SwitchOffUiTextResources x:Key="DeactivatableUiText"/> 
    <SwitchOffConverter x:Key="ToolTipSwitcher"/> 
</Resources> 

и

public static class ToolTipSwitch 
{ 
    private static bool s_isToolTipActivated = true; 
    public static bool IsToolTipActivated 
    { 
     get { return s_isToolTipActivated; } 
     set 
     { 
      if (s_isToolTipActivated != value) 
      { 
       s_isToolTipActivated = value; 
       RaiseIsToolTipActivatedChanged(); 
      } 
     } 
    } 

    private static void RaiseIsToolTipActivatedChanged() 
    { 
     var handlers = IsToolTipActivatedChanged; 
     if (handlers != null) handlers(); 
    } 

    public static event Action IsToolTipActivatedChanged; 
} 

public class SwitchOffConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     return ToolTipSwitch.IsToolTipActivated ? value : null; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotSupportedException(); 
    } 
} 

public class SwitchOffUiTextResources : INotifyPropertyChanged 
{ 
    public SwitchOffUiTextResources() 
    { 
     ToolTipSwitch.IsToolTipActivatedChanged += OnIsToolTipActivatedChanged; 
    } 

    private void OnIsToolTipActivatedChanged() 
    { 
     RaisePropertyChanged("LocalizedText"); 
    } 

    private UiTextResources m_localizedText = new UiTextResources(); 

    public UiTextResources LocalizedText 
    { 
     get { return ToolTipSwitch.IsToolTipActivated ? m_localizedStrings : null; } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 

    private void RaisePropertyChanged(string propertyName) 
    { 
     PropertyChangedEventHandler handler = PropertyChanged; 
     if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); 
    } 
} 

Второе решение: написать свой собственный DeactivatableToolTipService в виде тонкой оболочки вокруг S ilverlight ToolTipService и используйте только свой сервис. Если служба отключена, просто установите для всех всплывающих подсказок значение null. Я бы выбрал этот второй подход.

<Button 
    Command="{Binding VerifyDocument}" 
    DeactivatableToolTipService.ToolTip="{Binding ...anything...}"/> 
+0

Я попытался использовать SwitchOffConverter, и он отлично работает! Спасибо! – elias

Смежные вопросы