How do I make clickable text - c#

I have been trying to create buttons on Windows Phone 8, which don't look like buttons, but just look like text, however, I haven't been able to find this question answered anywhere else. I am trying to create something like what Microsoft have used below for the camera roll, albums and date buttons below. Is anybody able to explain how I can do this, or maybe link me to a tutorial or something that I may have missed while searching? Thank you.

Windows phone uses XAML code to create UIElements. Very similar to WPF, you can use almost any UIElement as a button. This is because each element has a large amount of events that can be tracked. Think of it as a layered cake. If you have a textblock inside of a listbox inside of a grid, similar to what you see above. Then when someone clicks on the textblock it will try to handle the event. If it isn't set to handle it then the listbox tries. If the listbox cant then the grid tries and so on. What you are looking for is the tap event in the textblock. Google textblock tap event.
<Grid x:Name="LayoutRoot" Background="Transparent">
<ListBox>
<StackPanel>
<TextBlock Tap="title_Tap_1" Name="title">title</TextBlock>
private void title_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
//Your code here
}

I tend to use a ListBoxItem to wrap a TextBlock. It allows you to use the TiltEffect from the wpToolkit to show interaction and also exposes a Tap event for the ListBoxItem
<ListBoxItem toolkit:TiltEffect.IsTiltEnabled="True" Tap="On_Tap">
<TextBlock>Hello World</TextBlock>
</ListBoxItem>

I don't know for Windows Phone 8 because I haven't written any app yet. I think that this is like Windows Phone 7 , 7.1 that I used to write code. This control that you see is a ListBox and inside there are ListBoxItems. ListBoxItem can be anything (it can be used as a container to insert anything inside it.). Hope it helps.

The easiest way is to use HyperlinkButton instead of classic Button. In that print screen I doubt there's a list for only like... 3 buttons (hyperlinkbuttons).

Controls in the xaml world are look-less: use a button in your ItemTemplate and turn the border off. Then you can use the command property of the button for binding to your VM, or if you are not using MVVM use the Click event of the button and handle it in the code behind.

Related

How to disable MaterialDesignInXaml Button animation?

I'm trying to create a button in WPF with MaterialDesignInXaml installed, without the animation when clicking it:
I've already looked through each property of the button and took a look at the buttons source code, but haven't found a solution.
The problem is, that the animation exceeds the rounded window.
I'm still quite on the beginner level of designing with xaml
Set the RippleAssist.Feedback attached property to Transparent:
<Button materialDesign:RippleAssist.Feedback="Transparent" Content="..." />

How to display button over a Ad Mediator in windows phone 8?

I use in the application Ad Mediator. I need to add a button(see example)
I tried to use the Canvas and Canvas.Zindex. But then does not display advertising. Please tell me how to do it.
Just embed it in a panel like Grid so it just follows the DOM. Something like (in pseudo);
<Grid>
<AdMediator/>
<Button/>
</Grid>

Metro application directly focuses on my first field

I'm creating this test Metro application using Windows 8, VS2012, C# and XAML. There are different TextBox in the application page arranged in a StackPanel. When the application is launched the focus is on the first TextBox.
I was wondering how to "deactivate" this.
Here's a pic, as you can see the first field is focused (color changed and ToolTip displayed).
When your UI is loaded you can remove focus from the TextBox by applying a Programmatic focus state to any other control.
Imagine that you have a Button named myButton. You can:
myButton.Focus(FocusState.Programmatic);
You cannot however use FocusState.Unfocused state to remove focus from the TextBlock because it is not allowed and will throw an exception.
One simple fix for this is place something to catch it first with IsTabStop="True" with a 0 Opacity which is a bit hacky but the only way I know. So something like;
<TextBox IsTabStop="True" Opacity="0" Height="1" Width="1"/>
<!-- Then the rest of your content like your other TextBox stuff -->

Textblock text selection

I have a chat window where each message is a TextBlock. I want to be able to select the text inside my TextBlocks. Google says to use a TextBox instead, which I cannot do because they do not support runs, which I am using to create hyperlinks inside my messages. What options do I have?
Check out the RichTextBox implementation for WPF.
How about making an CustomContentControl with TextBox (with selection style) and a Link in it and play with visibility based on content. Some thing like
<myControls:CustomContentControl>
<Grid>
// play with visibilty depending on content.
<CustomLink/>
<TextBox Style="{StaticResource SelectionStyle}"/>
</Grid>
</myControls:ContentControl>

Silverlight 4: How to find source UI element from contextmenu's menuitem_click?

I have a datagrid and I added silverlight 4 toolkit contextmenu to textbox in datagrid as follows. When users right click on the textbox, contextmenu is being displayed. When users click the menu item with Header "Test", "MenuItem_Click" is getting executed. Now I want to access the textbox from the MenuItem_Click and modify its properties like background etc. Is there anyway to find textbox element(which is contextmenu's parent) from MenuItem_Click event?
It appears to me that I am missing something very simple.
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding AcctId}"
Style="{StaticResource documentTextBoxStyle}"
ToolTipService.ToolTip="Right Click to modify parameters" >
<toolkit:ContextMenuService.ContextMenu >
<toolkit:ContextMenu >
<toolkit:MenuItem Header="Test" Click="MenuItem_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</TextBox>
</DataTemplate>
There's really no need for a workaround, it's as simple as using the databinding:
(sender as MenuItem).DataContext as TextBox
Will give you the TextBox you're after. (Storing stuff in the Tag field is really not something you want to clutter your code with.)
Though I did not find a solution to this, I found couple of workarounds
Traverse the visual tree and findout the textbox
Modify the code in control toolkit sources to expose the internal member 'Owner' as a public Property which contains reference to the owner of the context menu, in my case, the textbox.
I wonder why SL toolkit guys made the owner to be internal not public. Probably their idea is to manage 'ContextMenu' only through 'ContextMenuService' but unfortunately ContextMenuService doesnt give the Owner. Hopefully SL toolkit guys will give us a way to get the owner of the context menu in future releases.
I'm not sure if this works in Silverlight, but I had a similar issue with WPF recently. If you use the ContextMenu's PlacementTarget property, it should return the element that was used to open the ContextMenu.
All I can suggest is giving your MenuItem a Tag with it's parent's TextBlock name like this:
EDIT: Can't figure out how to paste in Xaml, but I'm sure you know how to add this.
Then in your click event you find the TextBlock:
private void MenuItem_TextBlockClick(object sender, RoutedEventArgs e)
{
MenuItem menuItem = (MenuItem)sender;
TextBlock textBlock = this.FindName((string)menuItem.Tag) as TextBlock;
/// do something
}
The issue I found was the parent of the MenuItem is ContextMenu, which is fine. But once you try and get the Parent of the ContextMenu it just crashes.

Categories