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...
Related
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>
I want to have a textbox "popup" when I start to type something in my window, and when the textbox is empty have it collapsed.
Here's my current xaml:
<TextBox DockPanel.Dock="Top" Margin="2,0,3,2" x:Name="PopupSearchBox"
Visibility="{Binding SearchFilter.Length,Converter={StaticResource _BooleanToVisibilityConverter}}"
Text="{Binding SearchFilter,UpdateSourceTrigger=PropertyChanged}" />
Which seems to be working, but how can I have it receive input when it's collapsed so it can process it and become visible?
I need to create a button with two lines of text:
The first one is Command Title like "Save"
The second one is a Description of the Command like "The application state will be saved"
So I have written the next xaml:
<Button Margin="0,128,0,0" Padding="10,5" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<StackPanel Margin="0" UseLayoutRounding="False">
<TextBlock FontSize="{StaticResource PhoneFontSizeMediumLarge}" FontFamily="{StaticResource PhoneFontFamilySemiBold}">Save</TextBlock>
<TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Margin="0">The application state will be saved</TextBlock>
</StackPanel>
</Button>
This code working well except a one issue. The Description line becomes invisible when the button is pushed.
I'm sure the root cause is the low contrast color of the description line. But I don't know how to fix it.
Update: I have tried to use the PhoneTextSubtleStyle style but still have the same issue.
You could retemplate the Button (using the Control.Template property) to look different so that when pushed it no longer interferes with the content.
Could you try something like this
System.Windows.Visibility.Visible;
System.Windows.Visibility.Hidden;
or
System.Windows.Visibility.Collapsed
here is a link that will show an example of how to use this inside of a StackPanel
How to: Change the Visibility Property
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.
Backgorund
I am currently writing a program that allows a user to select a manufacture from a combo box. The combo box is created in wpf using the following wpf code segment:
<ComboBox Height="23" Margin="40.422,128.423,229.908,0" Name="itemProductManufacture" ToolTip="Click to open drop down menu" VerticalAlignment="Top" Text="Select A Manufacture" SelectionChanged="itemProductManufacture_SelectionChanged" DropDownOpened="itemProductManufacture_DropDownOpened">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ManufactureId}" Width="0"/>
<Image Name="itemManufactureImage" Source="{Binding ManufactureImage}" Height="15" Width="70" Stretch="Uniform"/>
<TextBlock Text="{Binding ManufactureName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
The data is provided form a database and each entry has a Image, a name and an Id (intentionally not shown)
Problem
I am trying to code the behaviour of the combo box so when it is open the image height is 50 and when it is closed it is 15 this is so the image is larger when it is first displayed and then smaller once selected so it doesn't take up too much space on the form.
I have tried editing the image propities using code but am unable to accsess it using its name or any other children of the combo box.
Thanks
Jonathan
As you are using data template you won't be able to access the directly by its name.
Try something like this -
Image image = this.itemProductManufacture.ItemTemplate.FindName("itemManufactureImage", this) as Image;
One thing I am not clear is whether you want to change image size for all the items or the selected one? If you need to access the image for a particulat item in combobox you may have to use the ItemContainerGenerator.ContainerFromItem, as explained in following posts -
WPF - ItemsControl - How do I get find my "CheckBox" item that is in the ItemTemplate?
http://www.sitechno.com/Blog/HowToUseAttachedPropertiesAsAnExtensionMechanismForACheckedListbox.aspx
look at this, To know the various ways of finding controls - How can I find WPF controls by name or type?
You can edit image properties from code using binding. Or you can use triggers in Datatemplate. When comboboxitems checked properties change, you can change height property of corresponding image
Try this:
<Image Height = "{Binding Path=IsDropDownOpen,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ComboBox}},
Converter={StaticResource myBoolToHeightConverter}}" />
An example for Converter here