এটিও আজ রাতে আমাকে পাগল করে তুলেছিল। আমি ToolTipইস্যুটি পরিচালনা করতে একটি সাবক্লাস তৈরি করেছি । আমার জন্য। নেট 4.0 এ, ToolTip.StaysOpenসম্পত্তিটি "সত্যই" খোলা থাকে না।
নীচের ক্লাসে, সম্পত্তি ToolTipEx.IsReallyOpenপরিবর্তে নতুন সম্পত্তি ব্যবহার করুন ToolTip.IsOpen। আপনি চান নিয়ন্ত্রণ পেতে হবে। Debug.Print()কলটির মাধ্যমে , আপনি ডিবাগার আউটপুট উইন্ডোতে দেখতে পারেন ঠিক কতবার this.IsOpen = falseবলা হয়! এত কিছুর জন্য StaysOpen, নাকি আমার বলা উচিত "StaysOpen"? উপভোগ করুন।
public class ToolTipEx : ToolTip
{
static ToolTipEx()
{
IsReallyOpenProperty =
DependencyProperty.Register(
"IsReallyOpen",
typeof(bool),
typeof(ToolTipEx),
new FrameworkPropertyMetadata(
defaultValue: false,
flags: FrameworkPropertyMetadataOptions.None,
propertyChangedCallback: StaticOnIsReallyOpenedChanged));
}
public static readonly DependencyProperty IsReallyOpenProperty;
protected static void StaticOnIsReallyOpenedChanged(
DependencyObject o, DependencyPropertyChangedEventArgs e)
{
ToolTipEx self = (ToolTipEx)o;
self.OnIsReallyOpenedChanged((bool)e.OldValue, (bool)e.NewValue);
}
protected void OnIsReallyOpenedChanged(bool oldValue, bool newValue)
{
this.IsOpen = newValue;
}
public bool IsReallyOpen
{
get
{
bool b = (bool)this.GetValue(IsReallyOpenProperty);
return b;
}
set { this.SetValue(IsReallyOpenProperty, value); }
}
protected override void OnClosed(RoutedEventArgs e)
{
System.Diagnostics.Debug.Print(String.Format(
"OnClosed: IsReallyOpen: {0}, StaysOpen: {1}", this.IsReallyOpen, this.StaysOpen));
if (this.IsReallyOpen && this.StaysOpen)
{
e.Handled = true;
// We cannot set this.IsOpen directly here. Instead, send an event asynchronously.
// DispatcherPriority.Send is the highest priority possible.
Dispatcher.CurrentDispatcher.BeginInvoke(
(Action)(() => this.IsOpen = true),
DispatcherPriority.Send);
}
else
{
base.OnClosed(e);
}
}
}
ছোট ভাড়া: মাইক্রোসফ্ট কেন DependencyPropertyপ্রোপার্টিগুলিকে (গেটার্স / সেটটার) ভার্চুয়াল তৈরি করে নি তাই আমরা সাবক্লাসে পরিবর্তনগুলি গ্রহণ / প্রত্যাখ্যান / সমন্বয় করতে পারি? বা virtual OnXYZPropertyChangedপ্রতিটি জন্য একটি করা DependencyProperty? বিতৃষ্ণা।
--- সম্পাদনা ---
এক্সএএমএল সম্পাদকের উপরে আমার সমাধানটি অদ্ভুত দেখাচ্ছে - টুলটিপটি সর্বদা দেখায়, ভিজ্যুয়াল স্টুডিওতে কিছু পাঠ্য অবরুদ্ধ করে!
এখানে এই সমস্যাটি সমাধানের আরও ভাল উপায়:
কিছু এক্সএএমএল:
<!-- Need to add this at top of your XAML file:
xmlns:System="clr-namespace:System;assembly=mscorlib"
-->
<ToolTip StaysOpen="True" Placement="Bottom" HorizontalOffset="10"
ToolTipService.InitialShowDelay="0" ToolTipService.BetweenShowDelay="0"
ToolTipService.ShowDuration="{x:Static Member=System:Int32.MaxValue}"
>This is my tooltip text.</ToolTip>
কিছু কোড:
// Alternatively, you can attach an event listener to FrameworkElement.Loaded
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
// Be gentle here: If someone creates a (future) subclass or changes your control template,
// you might not have tooltip anymore.
ToolTip toolTip = this.ToolTip as ToolTip;
if (null != toolTip)
{
// If I don't set this explicitly, placement is strange.
toolTip.PlacementTarget = this;
toolTip.Closed += new RoutedEventHandler(OnToolTipClosed);
}
}
protected void OnToolTipClosed(object sender, RoutedEventArgs e)
{
// You may want to add additional focus-related tests here.
if (this.IsKeyboardFocusWithin)
{
// We cannot set this.IsOpen directly here. Instead, send an event asynchronously.
// DispatcherPriority.Send is the highest priority possible.
Dispatcher.CurrentDispatcher.BeginInvoke(
(Action)delegate
{
// Again: Be gentle when using this.ToolTip.
ToolTip toolTip = this.ToolTip as ToolTip;
if (null != toolTip)
{
toolTip.IsOpen = true;
}
},
DispatcherPriority.Send);
}
}
উপসংহার: ক্লাস সম্পর্কে কিছু আলাদা ToolTipএবং ContextMenu। উভয়েরই "পরিষেবা" শ্রেণি রয়েছে, যেমন ToolTipServiceএবং ContextMenuServiceনির্দিষ্ট বৈশিষ্ট্যগুলি পরিচালনা করে এবং উভয়েরই Popupপ্রদর্শনের সময় "গোপন" পিতামাতার নিয়ন্ত্রণ হিসাবে ব্যবহার করা হয়। অবশেষে, আমি লক্ষ্য করেছি ওয়েবে সমস্ত এক্সএএমএল টুলটিপ উদাহরণ ToolTipসরাসরি ক্লাস ব্যবহার করে না । পরিবর্তে, তারা এস StackPanelসহ একটি এম্বেড করে TextBlock। যে জিনিসগুলি আপনাকে বলতে বাধ্য করে: "হুঁ ..."
ShowDuration, মনে করুন এটি এমন একটি30,000। এর থেকে বড় কিছু এবং এটি ডিফল্ট হয়ে যাবে5000।