2010-06-30 13 views
20

मैं कैसे सुनिश्चित कर सकता हूं कि बटन अक्षम होने पर बटन का टूलटिप केवल तभी दिखाई दे रहा है?डब्ल्यूपीएफ टूलटिप दृश्यता

मैं टूलटिप की दृश्यता को बाध्य कैसे कर सकता हूं?

+0

जब यह "आईएस" अक्षम हो जाता है? - क्या आपका मतलब "अक्षम नहीं है"? – 4imble

+8

यह टूलटिप प्रदर्शित करने का अर्थ हो सकता है कि आप इस बटन को क्यों नहीं छू सकते हैं। यदि वह डेविड का इरादा है, तो मुझे लगता है कि यह बहुत समझ में आता है। – reuscam

+1

हाँ, मुझे लगता है, मैं picky नहीं था। मैं वास्तव में दिलचस्पी थी :) – 4imble

उत्तर

28

बटन को निष्क्रिय होने पर टूलटिप दृश्यमान होने के लिए आपको बटन पर True पर ToolTipService.ShowOnDisabled सेट करने की आवश्यकता होगी। टूलटिप को सक्षम और अक्षम करने के लिए आप बटन पर ToolTipService.IsEnabled बाध्य कर सकते हैं।

+1

कोई भी जो मेरे जैसा ही काम करना चाहता है, मैंने बटन के लिए पूर्ण xaml को उत्तर के रूप में पोस्ट किया है। आपकी मदद के लिए धन्यवाद। –

20

इस बटन से भरा XAML है क्या डेविड वार्ड ने के लिए

<Button 
    x:Name="btnAdd" 
    Content="Add" 
    ToolTipService.ShowOnDisabled="True" 
    ToolTipService.IsEnabled="{Binding ElementName=btnAdd, Path=IsEnabled, Converter={StaticResource boolToOppositeBoolConverter}}" 
    ToolTip="Appointments cannot be added whilst the event has outstanding changes."/> 
3

एक थोड़ा संशोधित जवाब (@Quartermeister के जवाब के आधार पर)। यहाँ पूर्ण कोड

resouces के लिए एक मूल्य कनवर्टर जोड़े इस

<Window.Resources> 
    <Converters:NegateConverter x:Key="negateConverter"/> 
</Window.Resources> 

की तरह फिर निम्नलिखित को परिभाषित है XAML

<Button 
    x:Name="btnAdd" 
    Content="Add" 
    ToolTipService.ShowOnDisabled="True" 
    ToolTipService.IsEnabled="{Binding RelativeSource={RelativeSource self}, Path=IsEnabled, Converter={StaticResource negateConverter}}" 
    ToolTip="Hi guys this is the tool tip"/> 

मूल्य कनवर्टर इस

[ValueConversion(typeof(bool), typeof(bool))] 
    public class NegateConverter : IValueConverter 
    { 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
    return !((bool)value); 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
    } 
8

आप कर सकते हैं की तरह लग रहा इसे एक साधारण ट्रिगर का उपयोग करके भी करें। बस विंडो के निम्नलिखित टुकड़े को एक विंडो में रखें।

<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center"> 
    <CheckBox Name="chkDisabler" Content="Enable/disable button" Margin="10" /> 
    <Button Content="Hit me" Width="200" Height="100" IsEnabled="{Binding ElementName=chkDisabler, Path=IsChecked}"> 
     <Button.Style> 
      <Style TargetType="{x:Type Button}"> 
       <Setter Property="ToolTipService.ShowOnDisabled" Value="true" /> 
       <Setter Property="ToolTip" Value="{x:Null}" /> 
       <Style.Triggers> 
        <Trigger Property="IsEnabled" Value="False"> 
         <Setter Property="ToolTip" Value="Hi, there! I'm disabled!" /> 
        </Trigger> 
       </Style.Triggers> 
      </Style> 
     </Button.Style> 
    </Button> 
</StackPanel> 
+0

'स्टाइल' सेटटर के माध्यम से 'ShowOnDisabled' को सेट करने के लिए वाक्यविन्यास देखने के लिए यह आसान था। – mungflesh

संबंधित मुद्दे