Textbox tag and IsHitTestVisible property - c#

<TextBox Foreground="Black"
FontFamily="Times New Roman"
FontWeight="Bold"
FontSize="15"
MaxHeight="50"
Margin="6,95,40.067,0"
Name="txt1" VerticalAlignment="Top"
IsHitTestVisible="False"
Height="30"
Grid.Row="4"
Grid.Column="2"/>
What is the role of IsHitTestVisible property on TextBox?

When you have a control inside another control, like, If you have a TextBox inside... lets say, another TextBox. Then by setting the isHitTestvisible property of the parent control to False you allow the user to type in the child TextBox. If you set it to True then the RoutedEvent will be handled at the parent control level.
This property is mostly used when you work with Adorners.

Check this posts
http://social.msdn.microsoft.com/Forums/en/wpf/thread/7c352827-b4ed-493c-8a68-58179ad801fc
http://msdn.microsoft.com/en-us/library/system.windows.uielement.ishittestvisible.aspx

true if this element could be returned as a hit test result from at least one point; otherwise, false. The default value is true.
Source: MSDN
See also: Hit Testing in the Visual Layer

Related

Need to modfy the default tab order of child elements

I have custom control like below. When press tab key focus will move in the order elements arrangement.
Query:
When stackpanel receive tab focus I need to change default tab order toggle button present in stackpanel
Default Tab Order:
DockPanel--Border---StackPanel-->Button1-->button2-->button3
Expected Order
DockPanel--Border---StackPanel-->Button3-->button2-->button1
I need update TabOrder based on its parent. Please suggestion solution modify the tab order based on parent
Note: I need UI as like below arrangements, only i need to modify the tab order for buttons
<DockPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Border x:Name="MainBorder">
<StackPanel>
<ToggleButton>Button 1</ToggleButton>
<ToggleButton>Button 3</ToggleButton>
<ToggleButton>Button 3</ToggleButton>
</StackPanel>
</Border>
</DockPanel>
As mentioned in comments do set the TabIndex property. To step within control do use KeyboardNavigation.TabNavigation attached property.
<DockPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Border x:Name="MainBorder">
<StackPanel KeyboardNavigation.TabNavigation="Local">
<ToggleButton KeyboardNavigation.TabIndex="3">Button 1</ToggleButton>
<ToggleButton KeyboardNavigation.TabIndex="2">Button 2</ToggleButton>
<ToggleButton KeyboardNavigation.TabIndex="1">Button 3</ToggleButton>
</StackPanel>
</Border>
</DockPanel>
If you want to modify the tab order at run time I would advice you to create a behavior for it. See Use of Behavior in WPF MVVM? To access attached property from code see Get and set WPF custom attached property from code behind

How to change materialDesign: property in C# code?

I'm trying to change the property materialDesign:ButtonProgressAssist.IsIndeterminate via C# code.
I haven't found any property like that in the Button object.
This is the buttons code:
<Button x:Name="loginButton" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="0,0,0,100" Width="100"
Style="{StaticResource MaterialDesignRaisedButton}"
materialDesign:ButtonProgressAssist.Value="-1"
materialDesign:ButtonProgressAssist.IsIndicatorVisible="True"
materialDesign:ButtonProgressAssist.IsIndeterminate="false" />
I want to set the IsIndeterminate Property to true when it gets clicked.
I don't understand, why i always find it out shortly after i ask it on StackOverflow...
But here's the solution:
MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndeterminate(loginButton, true);

Binding a control's x:Name

When I add
<TextBlock Text="{Binding SettingName}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" />
Everuthing is ok. But when
<TextBlock x:Name="{Binding SettingTextBlockName}" Text="{Binding SettingName}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" />
constructor are breaking.
But I need different names in all elements.
x:Name is a special property. As a matter of fact it's not a property at all, it's an attribute that maps the name or id property of the element to x:Name. Binding only works when applied to a DependencyProperty, so it cannot work on x:Name. It must be set manually.
If you want to distinguish between objects in runtime, you can set the Tag attribute, which tolerates everything.
more on x:Name: http://msdn.microsoft.com/en-us/library/ms752290.aspx
You should use FrameworkElement.Tag property, according to MSDN
FrameworkElement.Tag gets or sets an arbitrary object value that can
be used to store custom information about this element.
What use is the Tag property in .net

ToolTip is null. How do I access it?

In my custom control I want to programmaticaly enable or disable tooltip depending on options. Here is how my icon defined in template:
<Image x:Name="PART_IconImage" Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Center" Source="{TemplateBinding Icon}"
ToolTipService.ToolTip="{TemplateBinding Caption}" />
I'm using this code to access ToolTip and to enable/disable it:
// Enable tooltip when caption not shown
if (this.IconImage != null)
{
var toolTip = ToolTipService.GetToolTip(this.IconImage) as ToolTip;
if (toolTip != null)
toolTip.IsEnabled = this.CaptionVisibility.HasValue
? (this.CaptionVisibility.Value == Visibility.Collapsed)
: (this.ParentToolbar.CaptionsVisibility == Visibility.Collapsed);
}
GetToolTip returns null. Any idea why?
P.S. I was following this advice here: How to programmatically access ToolTipService of a Silverlight FrameworkElement?
But it doesn't work for me.
Are you sure that ToolTipService.GetToolTip is returning null, as opposed to returning something other than a ToolTip?
I did a quick experiment with code similar to yours and found that ToolTipService.GetToolTip returned a string. I was of course binding ToolTipService.ToolTip to a string dependency property. I suspect you're also getting a string back from GetToolTip, but the as ToolTip you have added after the call to this method nulls out this string.
One way to programmatically disable the tooltip is to bind it to a property on the view-model which contains the tooltip text if the tooltip should be shown or null if the tooltip should not be shown.
Alternatively, you can use a ToolTip, instead of a string, as the tooltip for your control. That way you should be able to access the ToolTip object and enable/disable it in your code above:
<Image x:Name="PART_IconImage" Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Center" Source="{TemplateBinding Icon}">
<ToolTipService.ToolTip>
<ToolTip>
<TextBlock Text="{TemplateBinding Caption}" />
</ToolTip>
</ToolTipService.ToolTip>
</Image>
Why don't you simply bind property below with a bool property?
ToolTipService.IsEnabled
Then whenever you want to disable/enable simply change the binded property
< Image ToolTipService.IsEnabled="{Binding Path=SomeProperty}">
 
Also take a look at How do you disable tooltips in code at runtime

Silverlight Element Binding

I have a custom component, ExportCommandButton, that has two attached properties. This component is designed to be attached to a button. When clicked, the component would initiate the export method of the grid (Telerik RadGridView). The problem I have is how can I pass the grid to the component via one of the attached properties? I've tried element to element binding, but the GridView set property never fires. How do you bind to a control and not a property of the control?
<Button IsEnabled="{Binding Loaded}"
cmd:ExportCommandButton.GridView="{Binding ElementName=MyGrid}"
cmd:ExportCommandButton.Converter="{StaticResource MyConverter}">
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="/Assets/xls.png" />
<TextBlock VerticalAlignment="Center" Text="Export" Margin="5,0,0,0" />
</StackPanel>
</Button.Content>
</Button>
Your syntax seems right. The CLR property setter is not called because the binding directly updates the dependency property, without passing by the property which is here for convenience. Use the propertyChangedCallback parameter of your attached property metadata to listen for changes.

Categories

Resources