Is there a way to disable a tabindex on a wpf control? - wpf

I have a row of 5 expanders on the top of my page that I do not want to get to using the tab button. There is currently no tabindex but for whatever reason I'm able to get to it using the tab button. I've tried using IsTabStop = False and I've tried = True but neither make a difference. I've also tried setting TabIndex=0 but that didn't work either.
<Expander IsExpanded="{Binding ScrollTop_IsExpanded}" VerticalAlignment="Top" IsEnabled="True" Grid.Row="0" Grid.Column="4" ExpandDirection="Right" />
<Label Margin="2,0,2,0" Content="Top" FontSize="10" Grid.Row="0" Grid.Column="5" VerticalAlignment="Top" HorizontalAlignment="Left" />

You can set
KeyboardNavigation.TabNavigation="None"

Set KeyboardNavigation.TabNavigation="None" in your Expander
<Expander KeyboardNavigation.TabNavigation="None" IsExpanded="False" VerticalAlignment="Top" IsEnabled="True" ExpandDirection="Right" />

Related

WPF c# a button with a textbox

I need to create a button similar like below, it is a textbox and a button combined, you can click "Get Code" button and you will receive a SMS text with the code, then you can input the code in the textbox.
textbox and a button
anyone can help?
Hi, my current code is quite simple.
<Button
Grid.Row="2"
Grid.Column="0"
HorizontalOptions="Center"
Text="Get Code"
FontFamily="{ StaticResource IconsFontFamily }"
Style="{ StaticResource CircleActionButtonFlatStyle }"
micro:Message.Attach="[Event Clicked] = [Action SendVerifyCodeAsync()]"/>
<Entry
Grid.Column="1"
Grid.Row="2"
Grid.ColumnSpan="2"
VerticalOptions="Center"
HorizontalOptions="FillAndExpand"
Text="{Binding Code}"
Placeholder="Send Code" />
Has people said in comments, you need to wrap it in borders.
With this example, you just need to change the color for the ones you want, and then you can set Click events in the respective borders to make them act like buttons and do the respective actions. You can add the code micro:Message.Attach="[Event Clicked] = [Action SendVerifyCodeAsync()]" to the respective border.
Code:
<Border BorderBrush="Black" BorderThickness="1" Margin="10" CornerRadius="15">
<Grid Margin="-1">
<TextBox TextWrapping="Wrap" Text="Input code" Background="{x:Null}" BorderBrush="{x:Null}" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Center"/>
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Right" CornerRadius="15" Background="#FF39D3D3">
<TextBlock TextWrapping="Wrap" Text="Get Code" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0"/>
</Border>
</Grid>
</Border>
Example:

How to make textbox in toolbar stretchable

I have a wpf browser and I have a Textbox attached to a Toolbar. However, I find it impossible to make it strechable. The effect I'm looking for is the kind you see in Chrome. Try to resize your browser window and observe the search field and you will get what I mean.
The Toolbar is already extremely limited to all edits but I can't ignore the fact that it should be a soulution to this problem.
The only thing I accomplished so far is to make the Textbox scale based on the number of characters in it but that's not obviously what I want.
Additionally: My Toolbar stretches just fine.
My XAML code as follows:
<ToolBar HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="49" Width="auto">
<TextBox x:Name="Urlbox" Height="44" Margin="0" TextWrapping="Wrap" Text="Input URL" GotFocus="TextBox_GotFocus" KeyDown="OnKeyDownHandler" VerticalAlignment="Top" Width="260" HorizontalContentAlignment="stretch"/>
</ToolBar>
Remove Width="260" property from your TextBox. And add HorizontalAligment="Stretch".
Put your TextBlock into StackPanel or Grid which will do the trick.
<ToolBar HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="49" Width="auto">
<Grid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ToolBar}}, Path=ActualWidth}">
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Top" ... >
</Grid>
</ToolBar>
Your code as it stands has a number of things that mean the TextBox won't resize.
You've got a fixed width
You've set HorizontalContentAlignment="Stretch" but not HorizontalAlignment="Stretch" on the TextBox
You've set HorizontalAlignment="Stretch" but not HorizontalContentAlignment="Stretch" on the ToolBar
<ToolBar HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Top" Height="49" Width="auto">
<TextBox x:Name="Urlbox" Height="44" Margin="0" TextWrapping="Wrap" Text="Input URL" GotFocus="TextBox_GotFocus" KeyDown="OnKeyDownHandler" VerticalAlignment="Top" HorizontalContentAlignment="stretch" HorizontalAlignment="stretch"/>
</ToolBar>
Failing that, as others have said, you can try placing a Grid (not a StackPanel) inside the ToolBar and the TextBox within that Grid. A Grid will automatically take up as much space as it is given by its parent (equivalent of Width="*"), whereas a StackPanel will only take up as much space as its content requires (equivalent of Width="Auto").

Why won't the WPF progressbar stretch to fit?

This is my original code:
<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<ProgressBar Height="23" Name="searchProgressBar" Foreground="Blue" BorderBrush="#00000000" BorderThickness="1" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
<TextBlock Text="asdf" Height="23" Name="progressTextBlock" VerticalAlignment="Top" Foreground="Red" HorizontalAlignment="Right"/>
</StackPanel>
The progressbar was very small, maybe 2 or 3 pixels wide, then there was the text block and empty space after. So I tried explicitly docking the elements to sides:
<DockPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" >
<ProgressBar DockPanel.Dock="Left" Height="23" Name="searchProgressBar" Foreground="Blue" BorderBrush="#00000000" BorderThickness="1" VerticalAlignment="Top" />
<TextBlock DockPanel.Dock="Right" Text="asdf" Height="23" Name="progressTextBlock" VerticalAlignment="Top" Foreground="Red" HorizontalAlignment="Right"/>
</DockPanel>
No avail. I also tried modifying each solution by setting HorizontalAlignment="Stretch" on the progress bar, but there's no change. How do i stretch it to fill all the space there is after the text block has been rendered?
Remove DockPanel.Dock="Left" from the ProgressBar and switch the order of the controls:
<DockPanel>
<TextBlock DockPanel.Dock="Right" Height="23" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<ProgressBar Height="23" VerticalAlignment="Top" />
</DockPanel>
By default, DockPanel has its property LastChildFill set to true, which will make the ProgressBar take the available space.
ahh I see what you're trying to do. This is probably a better place to use a grid with 2 column definitions. The first(the left one) columndefinition with Width="*" and the second(the right one) with a width set to Width="Auto". For more info about auto vs * see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9a7e6591-1fae-4295-b68a-be97e8e53d06/

How to make a WPF ComboBox to handle click on an overlying TextBlock?

I have a TextBlock which is over a ComboBox and I want the combobox popup (dropdown) apear when I click on it.
<Grid>
<ComboBox Name="tstcmb" Height="27" HorizontalAlignment="Left" Margin="29,92,0,0" VerticalAlignment="Top" Width="131" SelectedIndex="1" >
<ComboBoxItem>a</ComboBoxItem>
<ComboBoxItem>aaaa</ComboBoxItem>
</ComboBox>
<TextBlock Text="skdkdkdk" Background="Green" Height="16" HorizontalAlignment="Left" Margin="29,92,0,0" VerticalAlignment="Top" Width="131" />
</Grid>
Is it possible?
Set IsHitTestVisible="False"
<TextBlock IsHitTestVisible="False".../>
In that way the TextBlock doesn't intercept mouse clicks and allows them to be handled by the ComboBox underneath.

Tab order and index in WPF using the MVVM pattern

I'm having an issue with tabbing through the controls on a WPF application using the MVVM pattern. I have the following XAML which defines a tree structure
<Grid Background="Transparent" Margin="10">
<TreeView ItemsSource="{Binding FirstLevelNavigableViewModels}" Background="Transparent"
HorizontalContentAlignment="Stretch"
HorizontalAlignment="Stretch"
BorderThickness="0"
ItemContainerStyle="{StaticResource TreeViewItemStyle1}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type ViewModel:VendorViewModel}" ItemsSource="{Binding Children}">
<View:VendorView HorizontalContentAlignment="Stretch" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type ViewModel:ProductViewModel}">
<View:ProductView HorizontalContentAlignment="Stretch" />
</DataTemplate>
</TreeView.Resources>
</TreeView>
</Grid>
When the treeview is loaded, the XAML for the "ProductView" is as follows
<Border Margin="0,2,2,2" CornerRadius="3" Background="#3FC7B299" DockPanel.Dock="Right" HorizontalAlignment="Right" Width="109">
<StackPanel Orientation="Vertical" Margin="6,4">
<DockPanel>
<TextBlock DockPanel.Dock="Left" FontFamily="Segoe" FontSize="10" FontWeight="Medium"
Foreground="Black" Opacity="0.75"
Text="CALC. REG. PRICE"></TextBlock>
<Button Width="10" Height="10" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Padding="-4" Margin="0" Command="{Binding UserDefinedRetailPriceCommand}" Visibility="{Binding UserDefinedRetailPriceButtonView}">
<Image Width="10" Height="10" Source="/Arhaus.Pricing.Client;component/Styles/Images/error.png"></Image>
</Button>
</DockPanel>
<TextBox FontFamily="Segoe" FontSize="16" FontWeight="Medium" KeyboardNavigation.IsTabStop="True" KeyboardNavigation.TabIndex="{Binding RegularPriceTabIndex}"
Foreground="Black" Opacity="0.9" KeyboardNavigation.TabNavigation="Continue"
ebf:LostFocusBehaviour.LostFocusCommand = "{Binding LostFocusSugg}"
Text="{Binding NewSuggestedRetailPrice,Converter={StaticResource FormattingConverter}, ConverterParameter=' \{0:C\}', Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Background="#FFE6DED3" BorderBrush="#FFE6DED3" DataContext="{Binding StringFormat=\{0:c\}, NotifyOnValidationError=True}" Padding="0" TabIndex="1"></TextBox>
</StackPanel>
</Border>
I have the Tab Index bound to an integer that is ever increasing and bound as the treeview is loaded (I.E. I have it setup as tab index 1, 2, 3 etc. as each successive model is loaded).
I would like to be able to hit tab and jump to the next textbox in the treeview but when I click the TAB key, nothing happens. I'm not sure if I have the tabbing setup correctly but I'm very new to WPF and at a loss as to where and how to set the tabbing to make it work. I'm used to WinForms where you just set the tab index and go from there.
Thank you for your assistance, I apologize for the large code block.
I don't have a solution ready but some thoughts that maybe may help:
I don't know what RegularPriceTabIndex returns but probably it begins for each new TreeViewItem at the same index?
The same tab-index is given then multiple times because of repeating use of ProductView. Perhaps this leads to a problem. You can try setting FocusManager.IsFocusScope="true" for the ProductView. Maybe this helps.
Try also to set Control.IsTabStop="true" on the TextBox.

Resources