Increase hitbox size of textbox to show context menu - c#

I have a multiline textbox in which the right click context menu only appears if you right click on a line which contains text. I would like to expand the hitbox so that right clicking anywhere within the textbox will show the default context menu.
In the image below, I have highlighted the region in which the right click context menu works.
Here is the XAML for the textbox:
<TextBox Margin="3" VerticalContentAlignment="Top"
Cursor="IBeam"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"
TextWrapping="Wrap" AcceptsReturn="True"
AcceptsTab="True" SpellCheck.IsEnabled="True"
IsReadOnly="{Binding IsReadOnly}"
Text="{Binding CONFIDENTIAL}"
adonisExtensions:WatermarkExtension.Watermark="CONFIDENTIAL"
/>
Please let me know if there is additional information I can provide.

Related

How can I disable automatic focus on an element in wpf?

I am writing a WPF application using Infragistics package, which functionality requires opening new windows. One of the windows I open has 5 buttons on it. Buttons become highlighted when I focus on them. When I do not focus on any button, the first button is automatically in focus (it is highlighted like a focused button). I just want all the buttons have same style until I focus one of them.
I just didn't manage to find the solution.
Here is the part of code with the button
<DockPanel>
<ToolBarTray DockPanel.Dock="Top" IsLocked="True">
<ToolBar Name="toolBar" Band="1" BandIndex="1" BorderThickness="1" BorderBrush="LightSteelBlue">
<Button Name="button1" Click="button1_Click" BorderBrush="LightSteelBlue" Padding="3" IsEnabled="False" HorizontalContentAlignment="Left">
<StackPanel Orientation="Horizontal" >
<TextBlock VerticalAlignment="Center">Button 1</TextBlock>
</StackPanel>
</Button>
<Button HorizontalContentAlignment="Left" Margin="5,0,0,0" Name="button2" Click="button2_Click" BorderBrush="LightSteelBlue" Padding="5,3,5,3" ToolTip="Load and display debug data shot to check filtering process"
IsEnabled="False">
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center">Button 2</TextBlock>
</StackPanel>
</Button>
</ToolBar>
</ToolTray>
</DockPanel>
Now when I do not focus the mouse on any button, the button1 looks like it is focused. I want to look it as a button2.

Customize radio button in windows phone app

I have two radio button.I want to add a custom image for instead of a default style.
Example: I want to show image 1 for radio button which is selected and image 2 for all other radio button which are not selected.
The current radio button code, I have tried.
<RadioButton x:Name="rbCashFee" Content="Send with Cash out fee" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsChecked="True" Height="59" Foreground="Black" RenderTransformOrigin="0.5,0.5" Margin="8,0" Background="{x:Null}">
<RadioButton.RenderTransform>
<CompositeTransform/>
</RadioButton.RenderTransform>
</RadioButton>
<RadioButton x:Name="rbNCashFee" Content="Send without Cash out fee" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="59" Foreground="Black" Margin="8,0">
<RadioButton.BorderBrush>
<SolidColorBrush Color="#000"/>
</RadioButton.BorderBrush>
<RadioButton.Background>
<SolidColorBrush Color="#fff"/>
</RadioButton.Background>
</RadioButton>
Can some one kindly help me do this.
Your must change controls' templates.Read this article to understand how to do it.
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.control.template
Instead of trying to it in xaml I suggest you do it in the .cs file of that page by using SelectionChanged events and set the properties for your radiobutton dynamically in the .cs file.

Open popup at the location of the button clicked

I am trying to create a popup that opens similar to the window preview option in Windows 8 taskbar. Basically, when I click or hover on a button, it opens a popup with basic information just above the button. Here is an example.
Right now, I am able to open the popup at either the extreme left or extreme right side of the page, using the code below.
<Frame x:Name="PopUpFrame" HorizontalAlignment="Left" Visibility="Hidden" Height="400" Margin="10,10,0,0" Grid.Row="1" VerticalAlignment="Bottom" Width="400" Source="/BasicApp;component/StandingOrderPopUp.xaml" NavigationUIVisibility="Hidden"/>
I have 3 different buttons in the button bar, so I cannot set the fixed margin. I am trying to set the same in code but I am unable to get the absolute position and convert it to margin property. I am not sure, if there is a better solution either.
Edit:
Tried using popup but it doesn't open on button click.
<Popup x:Name="PopUpFrame" Placement="Top" PlacementTarget="{Binding ElementName=StandingOrderButton}" Width="400" Height="400">
<DockPanel Background="#770081a7">
<Canvas DockPanel.Dock="Bottom" x:Name="PopupButtonBar" Height="50" VerticalAlignment="Bottom">
<Button Height="30" Width="125" HorizontalAlignment="Right" VerticalAlignment="Center" Canvas.Top="10" Content="CLOSE" Foreground="White" Background="#ff0081a7" BorderBrush="White" FontFamily="Trebuchet MS" Canvas.Left="10" />
</Canvas>
<Label Margin="5,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DockPanel.Dock="Top" Content="STANDING ORDERS" Foreground="#ffffffff"></Label>
<Grid DockPanel.Dock="Top">
<Border BorderThickness="2" BorderBrush="#FFff7a00"></Border>
<RichTextBox Margin="2" Foreground="#FF0081a7" FontFamily="Trebuchet MS" IsEnabled="False"/>
</Grid>
</DockPanel>
</Popup>
And here is the event handler.
Private Sub StandingOrder_Click(sender As Object, e As RoutedEventArgs)
PopUpFrame.Visibility = Windows.Visibility.Visible
End Sub
Edit:
Never mind. I am an idiot. Instead of setting IsOpen property, I set the visibility. :(
It works perfectly, although, I had to copy the whole design from the separate page to this one. Still better than nothing. Only problem now is if I click on something else, I will have to write code to make sure popup is closed.
You can use a Popup control, coupled with it's Placement property to display your popup based on the current location of your buttons.
<Popup Placement="Top" PlacementTarget="{Binding ElementName=yourButton}" ... />
Inside your Popup, you can place your UserControl or any content element which will act as the popup's content.
See here for further information on popup placements, and here for a tutorial on WPF Popup controls.
Think about using ContextMenu, and set it's content you whatever you want. Thats is the solution for you.
This is how i defined one of my popups:
<Popup x:Name="btnPowerPopup" Placement="Mouse" StaysOpen="False">
....
</Popup>
you can user from the code behind on a button click or something :
btnPowerPopup.IsOpen = true;
and when the job is done:
btnPowerPopup.IsOpen = false;
But StaysOpen="False" let's you close the PopUp when clicking somewhere else.

Scrollviewer panning position on touch

I have a scrollviewer in which I have 2 WrapPanels. I would like to know how I would go about getting the scroll viewer position once a user scrolled to the last end of the last panel. I am trying to show and hide an on screen arrow that indicates there is more content, but off to the right of the screen, but I would like to hide the button once they get to the end of the scroll viewer.
Can someone point me in the direction of what I would do in the code behind to get the horizontal offset position of the scrollviewer based on the panning. Mainly I want to get the far right position and hide the Arrow button when it gets to that point. My width for each Panel is currently 1920, so the window is currently 1920 width which hides the next panel in the Stack.
My XAML currently is below:
<ScrollViewer x:Name="scrVwrProductCategories" Style="{DynamicResource scrVwrFullWidthHorizontal}" PanningMode="HorizontalOnly" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled">
<StackPanel Width="Auto" Height="750" HorizontalAlignment="Right" Orientation="Horizontal">
<WrapPanel Style="{DynamicResource wrpPnlProductCategoriesPanels}" x:Name="wrpPnlProductCategories">
<!-- Constant currently for count of buttons per WrapPanel = 6-->
<!-- This is filled in dynamically at runtime
<controls:btnLarge Height="325" Width="500" Margin="20,0" TitleText="My Item" NoteText="" ShowNote="Collapsed" ShowSubTitle="Collapsed"/>
-->
</WrapPanel>
<WrapPanel Style="{DynamicResource wrpPnlProductCategoriesPanels}" x:Name="wrpPnlProductCategories2">
<!-- Constant currently for count of buttons per WrapPanel = 6-->
<!-- This is filled in dynamically at runtime
<controls:btnLarge Height="325" Width="500" Margin="20,0" TitleText="My Item" NoteText="" ShowNote="Collapsed" ShowSubTitle="Collapsed"/>
-->
</WrapPanel>
</StackPanel>
<Kiosk:SwipeForMoreArrow x:Name="ctrlSwipeForMoreArrow" HorizontalAlignment="Right" VerticalAlignment="Center" Visibility="Collapsed"/>
</ScrollViewer>
Do you aim to make this possible only through XAML? Otherwise you could try to get the this.HorizontalOffset of the Scrollviewer via the OnScrolledChanged Event to identify wether it´s 0 or max.
Maybe this link might help too:
How to find that ScrollViewer is scrolled to the end in WPF?

Get previous item in grid winrt

<Grid x:Name="gridGeneralProperties" HorizontalAlignment="Left" Height="613" Margin="233,5,0,0" Grid.Row="1" VerticalAlignment="Top" Width="437">
<TextBlock TextWrapping="Wrap" Text="General Properties" FontSize="16" Margin="162,10,18,573"/>
<TextBlock TextWrapping="Wrap" Text="Name" Margin="10,69,298,521" FontSize="14.667"/>
<TextBox TextWrapping="Wrap" Text="{Binding Document.DocumentName}" IsReadOnly="True" Margin="144,59,73,520"/>
<AppBarButton x:Name="appBarButtonEditName" HorizontalAlignment="Left" Label="" Margin="349,39,-12,0" VerticalAlignment="Top" Icon="Edit" Height="75"/>
</Grid>
Is there a way to access the previous in a grid? In this case, if a user clicks on the AppBarButton, I want to make the previous TextBox editable. In all instances of where the button is clicked, the previous item will be a TextBox.
In your case - you know which one is previous in your XAML - you can simply name it to access it.
The general solution would be to get the index of the starting element in the Grid.Children collection and the previous one will be at index - 1.
MVVM is the way to go though. I'm also not sure why you would need a button to make a TextBox editable - just leave it editable always and you save the space.

Categories

Resources