Dynamically Adding child controls to a silverlight textbox - c#

Please forgive this stupid question. (I'm originally an ASP.NET programmer.)
I'm trying to add a telerik context menu to a textbox control in the code behind.
Adding it in the xaml is very easy (this works)
<TextBox AcceptsReturn="True" Text="{Binding Mode=TwoWay, Path=Description}" TextWrapping="Wrap" x:Name="txtIssues" Width="280" Height="100" VerticalScrollBarVisibility="Auto">
<telerikNavigation:RadContextMenu.ContextMenu>
<telerikNavigation:RadContextMenu x:Name="contextMenu"
ItemClick="ContextMenuClick">
<telerikNavigation:RadMenuItem Header="Set Vista as Background" />
<telerikNavigation:RadMenuItem Header="Set Beach as Background" />
<telerikNavigation:RadMenuItem Header="Set Forest as Background" />
</telerikNavigation:RadContextMenu>
</telerikNavigation:RadContextMenu.ContextMenu>
</TextBox>
However I would like to completely add the the control from c# code and I can't find a why to add a control to a textbox. I've been looking for something like "txtIssues.Children.Add" but there doesn't seem to be an option.

First its best you understand that you are not adding a control to the TextBox. The RadContextMenu.ContextMenu is not a control it is an attached property.
Funnily enough the Telerik documentation describes adding a context menu to a textbox in C#. See Working with the RadContextMenu. Sometimes "RTM" is actually good advice.

Related

Overlay over WebBrowser control

I have a TabControl (using InfragisticTabControl) where each TabItem contains a WebBrowser control where I can display a URL like www.google.com or any xbap UI.
Below is the TabItem Code:
<Grid>
<WebBrowser x:Name="myBrowser"
webHelper:WebBrowserHelper.BrowserSource="{Binding XBAP_URI}"
Height="Auto"/>
<Grid Name="MyOverlayGrid" Background="LightGray" Opacity="0.5"
Visibility="{Binding Path=IsEnabled, Converter={StaticResource BoolToVisible2}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDock:ContentPane}}}">
<TextBlock Text="User does not have permissions for this application" FontSize="24"/>
</Grid>
</Grid>
I verified using snoop that Visibility binding is correctly getting populated, but I don't see MyOverlayGrid on myBrowser control. I even tried updating Panel.ZIndex for MyOverlayGrid, no help.
Only thing that worked is to set myBrowser visibility to hidden (i used snoop) and then i could see MyOverlayGrid.
Can anyone tell me if I am doing something incorrect or missing something obvious? This works fine for a contentcontrol, may be its not possible for a WebBrowser control since the its starts new applictaion (InternetExplorer.exe or PresentationHost.exe) in the tab control?
Thanks,
RDV
Can anyone tell me if I am doing something incorrect or missing something obvious?
The latter am I afraid. The WebBrowser control is hosted in a separate HWND that is always drawn on top of the WPF elements as stated in the documentation on MSDN: https://msdn.microsoft.com/en-us/library/ms744952(v=vs.110).aspx.
There is nothing much you can do about this besides applying a workaround like for example putting your Grid in a Popup.
You may want to consider using some other third-party WebBrowser control such as for example Chromium.

Dragablz TabablzControl Visibility property not working

I'm using dragablz:TabablzControl in a project of mine and I have the need of hide/show some tabs dinamically.
The fact is the control is not respecting the property Visibility of the TabItem.
I've tried with and without binding, like this:
<dragablz:TabablzControl Grid.Row="2" BorderThickness="0" FixedHeaderCount="20">
<TabItem Header="Additional Info" Visibility="{Binding ShowAdditionalInfoTab, Converter={StaticResource BooleanToVisibilityConverter}}">
<controls:AdditionalInfoControl />
</TabItem>
<TabItem Header="Additional Info" Visibility="Collapsed">
<controls:AdditionalInfoControl />
</TabItem>
</dragablz:TabablzControl>
But none is working. Change the "FixedHeaderCount" does not affect the result.
The tab remains always visible.
Is there any other way that I can achieve the result I need?
I've received a response from the development team, and I'm leaving it here for anyone who has the same problem.
Yeah, obviously there’s since changes to the standard tab control to support all of the extra features, and currently that’s not supported. You’d have to temporarily remove your hidden item from the source.

Attach attribute to Scrollviewer of Textbox

I need to sync two scroll viewers in WPF, one of which is part of the TextBox item.
I intend on using the method described on CodeProject here:
However, this requires that I can attach attributes to both scrollviewers. One of the scrollviewers is the scrollviewer that comes as part of a textbox.
Code at the moment:
<ScrollViewer Core:ScrollSynchronizer.VerticalScrollGroup="V1">
<UIComponents:LineNumberBox
x:Name="LineBox"
VisibleLines="{Binding ElementName=CodeBox, Path=(UIComponents:VisibleLinesBinder.VisibleLines)}"
Padding="2,10,2,0"
FontSize="14"
Grid.Column="0"
/>
</ScrollViewer>
<UIComponents:SourceCodeBox
x:Name="CodeBox"
Padding="10"
FontSize="14"
Grid.Column="1"
UIComponents:VisibleLinesBinder.ObserveVisibleLines="True"
Core:ScrollSynchronizer.VerticalScrollGroup="V1"
/>
A UIComponents:SourceCodeBox is just a wrapper around a normal WPF Textbox.
Obviously the Core:ScrollSynchronizer.VerticalScrollGroup="V1" on the SourceCodeBox doesnt work? So how would I attach that attribute to the ScrollViewer within it? C# or XAML methods are both fine.
In case it makes any difference this is part of a User Control I am developing.
put the attatched behavior in a style like this:
<UIComponents:SourceCodeBox
x:Name="CodeBox"
Padding="10"
FontSize="14"
Grid.Column="1"
UIComponents:VisibleLinesBinder.ObserveVisibleLines="True"
Core:ScrollSynchronizer.VerticalScrollGroup="V1">
<UIComponents:SourceCodeBox.Resources>
<Style TargetType="ScrollViewer">
<Setter Property="Core:ScrollSynchronizer.VerticalScrollGroup" Value="V1"/>
</Style>
</UIComponents:SourceCodeBox.Resources>
</UIComponents:SourceCodeBox>

How to add sub menus to the ContextMenu control in Silverlight 4?

I have the following piece of XAML code:
<controlsInputToolkit:ContextMenuService.ContextMenu>
<controlsInputToolkit:ContextMenu
Height="75"
Width="200"
IsOpen="False"
Visibility="Collapsed"
Closed="mnuPopup_Closed"
x:Name="mnuPopup">
<controlsInputToolkit:MenuItem
x:Name="mnuAnswer911Call"
Header="Answer Call"
Click="mnuAnswer911Call_Click"
IsEnabled="True"/>
<controlsInputToolkit:MenuItem
x:Name="mnuHangup911Call"
Header="Hangup call"
Click="mnuHangup911Call_Click"
IsEnabled="True"/>
</controlsInputToolkit:ContextMenu>
</controlsInputToolkit:ContextMenuService.ContextMenu>
Let's say, based on context, I wanted to add a submenu to the mnuAnswer911Call menu item. How would I go about it?
The Silverlight Context Menu does not support submenus yet. But there are open source alternatives to help you achieve this. Here is one:
www.sl4popupmenu.codeplex.com

Disable Drag-drop from TextBox

I have a WPF textBox that is declared as ReadOnly
<TextBox IsReadOnly="True" IsTabStop="False" Width="200" />
So, User can not write anything into the TextBox or delete the content but it still allows user to drag the text from this textbox and drop it in any other textbox that caused the text removed from the first textbox(the read-only one) and thats unexpected. Is it a bug?
how can I get rid of this?
I tried the following code :
<StackPanel>
<TextBox IsReadOnly="True">Hello</TextBox>
<TextBox></TextBox>
</StackPanel>
When I drag-and-drop the text (after selection) from the first TexbtBox to the second one, the text is copied, but not removed from the first TextBox. I tried it under .NET 3.5 and .NET 4.0 targets.
If you want to get rid of your bug without trying to understand it (since it shouldn't happen), you can just put an empty control (Canvas will be ok) on top of your TextBox, with its Background property set to transparent.
<Grid>
<TextBox IsReadOnly="True" IsTabStop="False" Width="200" />
<Canvas Background="Transparent"/>
</Grid>
But the text won't be selectable anymore...

Categories

Resources