Product Bundles
DevCraft
All Telerik .NET and Kendo UI JavaScript components and AI Tools in one package.
Kendo UI
Bundle of AI Tools plus four JavaScript UI libraries built natively for jQuery, Angular, React and Vue.
Build JavaScript UI
Javascript
Telerik
Build modern .NET business apps
.Net Web
Cross-Platform
Desktop
Reporting and Documents
AI for Developers & IT
Ensure AI program success
AI Coding
AI Engineering
Additional Tools
Enhance the developer and designer experience
Testing & Mocking
Debugging
UI/UX Tools
CMS
Free Tools
Support and Learning
Productivity and Design Tools
Hi,
Would it be possible to have a editable RadComboBox TextBox Part to mimic the RadWatermarkTextBox with floating Label?
Got it.
public class WatermarkComboBox : RadComboBox { private RadWatermarkTextBox _waterTb; public override void OnApplyTemplate() { TextBox PART_EditableTextBox = Template.FindName("PART_EditableTextBox", this) as TextBox; Panel p = (Panel)System.Windows.Media.VisualTreeHelper.GetParent(PART_EditableTextBox); p.Children.Remove(PART_EditableTextBox); _waterTb = new RadWatermarkTextBox() { Name = "PART_EditableTextBox" }; MethodInfo methodToReplace = typeof(RadComboBox).GetMethod("GetTemplateChild", BF.NonPublic | BF.Instance); MethodInfo methodToInject = this.GetType().GetMethod("GetTemplateChild1", BF.Public | BF.Instance); Install(methodToReplace, methodToInject); p.Children.Add(_waterTb); var binding = new Binding { Source = this, Path = new PropertyPath(LabelProperty) }; _waterTb.SetBinding(RadWatermarkTextBox.LabelProperty, binding); base.OnApplyTemplate(); } public DependencyObject GetTemplateChild1(string childName) { if (childName == "PART_EditableTextBox") return _waterTb; return (DependencyObject)Template.FindName(childName, this); } // Credit: https://stackoverflow.com/a/36415711/1554806 public static void Install(MethodInfo methodToReplace, MethodInfo methodToInject) { RuntimeHelpers.PrepareMethod(methodToReplace.MethodHandle); RuntimeHelpers.PrepareMethod(methodToInject.MethodHandle); unsafe { if (IntPtr.Size == 4) { int* inj = (int*)methodToInject.MethodHandle.Value.ToPointer() + 2; int* tar = (int*)methodToReplace.MethodHandle.Value.ToPointer() + 2; #if DEBUG System.Diagnostics.Debug.WriteLine("\nVersion x86 Debug\n"); byte* injInst = (byte*)*inj; byte* tarInst = (byte*)*tar; int* injSrc = (int*)(injInst + 1); int* tarSrc = (int*)(tarInst + 1); *tarSrc = (((int)injInst + 5) + *injSrc) - ((int)tarInst + 5); #else System.Diagnostics.Debug.WriteLine("\nVersion x86 Release\n"); *tar = *inj; #endif } else { long* inj = (long*)methodToInject.MethodHandle.Value.ToPointer() + 1; long* tar = (long*)methodToReplace.MethodHandle.Value.ToPointer() + 1; #if DEBUG System.Diagnostics.Debug.WriteLine("\nVersion x64 Debug\n"); byte* injInst = (byte*)*inj; byte* tarInst = (byte*)*tar; int* injSrc = (int*)(injInst + 1); int* tarSrc = (int*)(tarInst + 1); *tarSrc = (((int)injInst + 5) + *injSrc) - ((int)tarInst + 5); #else System.Diagnostics.Debug.WriteLine("\nVersion x64 Release\n"); *tar = *inj; #endif } } } public string Label { get { return (string)GetValue(LabelProperty); } set { SetValue(LabelProperty, value); } } // Using a DependencyProperty as the backing store for Label. This enables animation, styling, binding, etc... public static readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(string), typeof(WatermarkComboBox), new PropertyMetadata(null)); } }