I'm creating a universal Windows Runtime App for Windows Phone 8.1 and Windows 8.1 using Xaml and C#.
I have inline hyperlinks setup as so -
<TextBlock Width="400" TextWrapping="Wrap">
<Span FontSize="20">
This is an example of how Hyperlink can be used in a paragraph of text. It might be helpful for you look to
<Hyperlink NavigateUri="http://www.bing.com">bing</Hyperlink>
for more answers in the future.
</Span>
</TextBlock>
This will display the text with a underline indicating the clickable hyperlink. However I want to indicate hyperlinks by color not underline as I can have multiple of them in a TextBlock.
I want to remove the underline from the inline Hyperlinks - TextDecorations property no longer exists in WP 8.1 and Windows 8.1 Store apps.
Note* I'm using Hyperlink element not HyperlinkButton as I need to have the links inline with text.
I would write a comment, but my reputation is not enough to do that.
I tried the same code on a blank both win 8.1 and win phone 8.1 project. However, the hyperlink is displayed with color by default, not with an underline as opposed to your project. My code is like below
<TextBlock Width="400" TextWrapping="Wrap">
<Span FontSize="20">
This is an example of how Hyperlink can be used in a paragraph of text. It might be helpful for you look to
<Hyperlink NavigateUri="http://www.bing.com" Foreground="#FF0007FF">bing</Hyperlink>
for more answers in the future.
</Span>
</TextBlock>
Could you try the Foreground property? Maybe it helps you.
In the final version of Windows 8.1 the Hyperlink-element doesn't have an underline. Maybe the confusion was caused by the focus border around the hyperlink? So the XAML:
<TextBlock Width="400" TextWrapping="Wrap" VerticalAlignment="Center">
<Span FontSize="20">
This is an example of how Hyperlink can be used in a paragraph of text. It might be helpful for you look to
<Hyperlink NavigateUri="http://www.bing.com">bing</Hyperlink>
for more answers in the future.
</Span>
</TextBlock>
Shows as:
One thing that can trick the viewer is that if the page doesn't have any other focusable items, the Hyperlink gets the focus and a border is drawn around it. This may look like it has underline:
If you want to get rid of that, add Button with Opacity 0 to the top of the page.
If you want to style the Hyperlink, you can overwrite it using the following keys:
<SolidColorBrush x:Key="HyperlinkDisabledThemeBrush" Color="#66000000" />
<SolidColorBrush x:Key="HyperlinkForegroundThemeBrush" Color="#FF4F1ACB" />
<SolidColorBrush x:Key="HyperlinkPointerOverForegroundThemeBrush" Color="#CC4F1ACB" />
<SolidColorBrush x:Key="HyperlinkPressedForegroundThemeBrush" Color="#994F1ACB" />
So if you have the following App.xaml.cs:
<Application.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="HyperlinkForegroundThemeBrush" Color="Green" />
</ResourceDictionary>
</Application.Resources>
You will get a green Hyperlink:
If you want the link to have underline, you can use the Underline-element. The XAML:
<TextBlock Width="400" TextWrapping="Wrap" VerticalAlignment="Center">
<Span FontSize="20">
This is an example of how Hyperlink can be used in a paragraph of text. It might be helpful for you look to
<Hyperlink NavigateUri="http://www.bing.com"><Underline>bing</Underline></Hyperlink>
for more answers in the future.
</Span>
</TextBlock>
And the result:
In my app I'm using
<Hyperlink TextDecorations="None" ...></Hyperlink>
to get rid of the underline.
Related
Hello I am trying to display data on labels and I want to provide extra details about the data, when the user clicks on a button e.g. .
I know there is the tag in html, where you can define a summary and the details below.
Is there a way, or even better a ContentView, which can do that in .NET MAUI?
I've thought about adding a temporary label under the summary label, with the details, but that looks weird and is not intuitive.
If by details you mean a collapse / expander (which seem to be what details is in html) you can use the expander from the .net maui community toolkit :
<Expander>
<Expander.Header>
<Label Text="Baboon"
FontAttributes="Bold"
FontSize="Medium" />
</Expander.Header>
<HorizontalStackLayout Padding="10">
<Image Source="http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg"
Aspect="AspectFill"
HeightRequest="120"
WidthRequest="120" />
<Label Text="Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae."
FontAttributes="Italic" />
</HorizontalStackLayout>
</Expander>
Otherwise if you just want to provide some additional texte about an element I would go with tooltips.
<Button Text="Save"
ToolTipProperties.Text="Click to Save your data" />
I am new to MAUI. And I haven't done anything complex with Xamarin as well.
The application I am testing with, has Shell navigation. And I can't find a way to change the toolbar items.
I would like to be able to change either the FontSize of the text, or the color of the SVG image. And I do not want those changes to affect the rest of my application, if possible. But if there is no other way, I can live with it.
I have managed to add styling to buttons, Labels etc... If styling is an option to this, it will be even better.
If I am on the wrong path, if you point me out why, I will be also grateful.
Thank you in advance!
If you want to just change a part of pages in your project. You can try to use a <Shell.TitleView> instead of the <Shell.ToolBarItem> in the content pages you want. Such as:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiAppTest.MainPage">
<Shell.TitleView>
<HorizontalStackLayout Margin="5" HorizontalOptions="End">
<Label Text="hello" TextColor="Red" FontSize="Medium" VerticalOptions="Center" HorizontalOptions="End" />
<Image Source="your image" Margin="10" Background="green"/>
</HorizontalStackLayout>
</Shell.TitleView>
You can change style of TabBar in Style.xaml in path \Resources\Style\. Search in file for Shell.TabBarForegroundColor. You will get TargetType="Shell" and this is style for AppShell.xaml.
I'm trying to build a UserControl in a UWP application and I'm not able to see its "Auto" size (based on its content) in the XAML-Designer.
I'm aware I can hardcode d:DesignHeight and d:DesignWidth to absolute values, but since the size should be based on its content, I don't want to hardcode the values.
Is there something like d:DesignHeight="Auto" / d:DesignWidth="Auto" ?
E.g. - for the sample User Control below
<UserControl
x:Class="MyCompany.UserControls.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:MyCompany.UserControls.UserControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel>
<Button Content="First" />
<Button Content="Second" />
</StackPanel>
</UserControl>
I'm seeing
However I'd like to see the size of the control based on its content.
Unfortunately, this is a limitation of the XAML designer. The control will still be sized properly at runtime.
However, this is a very good feedback and I suggest you send it as enhancement request in through Visual Studio feedback, I would definitely upvote it :-) .
If delete d:DesignHeight & d:DesignWidth in user control, it will layout as to it's content.
if it doesn't, then you can add VerticalAlignment & HorizontalAlignment to your user control while using.
<local:MyUserControl2 VerticalAlignment="Top" HorizontalAlignment="Left"
BorderBrush="Red" BorderThickness="1"/>
It should work.
Databinding still confues me and I am not sure how to essential make these controls repeat for each bound piece of data I have.
<Grid>
<TextBlock FontSize="25" Text="this is a header"></TextBlock>
<TextBlock Height="30" HorizontalAlignment="Left" Margin="19,36,0,0" Name="txt" Text="line under the header" VerticalAlignment="Top" />
<TextBlock Height="30" FontSize="25" HorizontalAlignment="Left" Margin="306,9,0,0" Name="textBlock2" Text="530" VerticalAlignment="Top" Width="91" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="305,42,0,0" Name="textBlock3" Text="30" VerticalAlignment="Top" Width="91" />
</Grid>
If my data source would have a count of 50. I would expect to see 50 of these groupings(I probably need to get a scroll bar though).
Not sure how to do this though. I need some sort of datatemplate I guess? Also "line under the header" should be clickable and highlight.
I think you need to use the control named "ItemsControl". Not a derived class, not a ListBox, just plain simple ItemsControl.
Either in code or in XAML, you set the ItemsControl's ItemsSource property to any collection containing your items.
In XAML (either in VS or Blend, to do it WYSIWYG in Blend you must somehow provide design data) you set the ItemsControl's ItemTemplate to a DataTemplate that contains the XAML subtree you want to repeat for every item in your collection.
Inside the DataTemplate, replace "line under the header" with the Button control, with Content="line under the header", and style it however you want. Then, add CallMethodAction to your button. It only takes 2 clicks in Blend, the first one is on "Assets" window. Specify TargetObject="{Binding}" MethodName="actSubtitleClicked". This way, the framework will call the void actSubtitleClicked() method of the item where user clicked the "line under the header".
For best performance, you should also modify the ItemsControl's ItemsPanel template, replacing StackPanel with VirtualizingStackPanel (again, a few clicks in Blend, the first one is the right click, then "Edit additional templates / ItemsPanel / Edit a copy")
I have customized the button in this way:
<Button BorderBrush="Transparent" Name="DialButton" Click="DialButton_Click" >
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="43" Name="lblNumber" Margin="0,-5,0,0" />
<TextBlock FontSize="12" Margin="5,20,0,0" Name="lblCharacter" />
</StackPanel>
</Button>
Now, when a user presses the button I want the OnPress state to change the color of the labels. I can do this if it's a simple button by changing the Pressed state. But my label is placed inside a stack panel. How can I change the color in this case? Or in which event can I change the colors of the labels from C#.
You can use the PropertyChangeAction in cases like this. You can find this in the behaviors category on the Assets tab in Expression Blend.
Apply this action on the labels. Change the trigger property to the DataTrigger instead of the default EventTrigger. Bind the trigger to the IsPressed property of the DialButton. Add two PropertyChangeActions per TextBlock and set the Value for one of the to true and the other one to false.
Here's an example for one of them. The other is exactly the same.
<TextBlock FontSize="43" x:Name="lblNumber" Margin="0,-5,0,0" Text="25">
<i:Interaction.Triggers>
<ec:DataTrigger Binding="{Binding IsPressed, ElementName=DialButton}" Value="true">
<ec:ChangePropertyAction PropertyName="Foreground">
<ec:ChangePropertyAction.Value>
<SolidColorBrush Color="Red"/>
</ec:ChangePropertyAction.Value>
</ec:ChangePropertyAction>
</ec:DataTrigger>
<ec:DataTrigger Binding="{Binding IsPressed, ElementName=DialButton}" Value="false">
<ec:ChangePropertyAction PropertyName="Foreground">
<ec:ChangePropertyAction.Value>
<SolidColorBrush Color="{StaticResource PhoneForegroundColor}"/>
</ec:ChangePropertyAction.Value>
</ec:ChangePropertyAction>
</ec:DataTrigger>
</i:Interaction.Triggers>
</TextBlock>
If the i: or ec: isn't working, make sure you've got these lines at the top of your xaml file.
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
You'll need to turn this into a custom control and then you can manage the styling of each component based on the state.
Try this in the click event of button
Button butClicked = (Button)sender;
StackPanel panel1 = (StackPanel)butClicked.Content;
var child1Panel1 = panel1.Children[0] as TextBlock;
child1Panel1.Foreground = new SolidColorBrush(Color.FromArgb(255, 18, 18, 18));
If you're only going to use this button once, probably the easiest way would be to open the .xaml file in Expression Blend, and use Blend to customize the button as you wish, including the state change. If you're using the button in more than one place, do as Matt suggested and make it a custom control (which you can also use Blend to design) that you can reuse.