InfoBar FontSize cannot be changed - c#

No changes occur when you try to
change the font size of the Message property of
the InfoBar class with the FontSize property.
Problem
Font size has not changed
Source Code
<InfoBar
Severity="Warning"
IsOpen="True"
FontSize="50"
Title="Data Requests"
Message="This is a test. FontSize at 50" >
</InfoBar>

This was a messy workaround that I tried and looks like it works, somehow.
<InfoBar x:Name="Notification"
IsOpen="true">
<InfoBar.Content>
<TextBlock
Text="Hello, world!"
Margin="0,-50,0,0"
FontSize="50"
/>
</InfoBar.Content>
</InfoBar>
You can add custom contents inside your bar. As you can see, I added a TextBlock and applied the changes. It works well with the icon and with the close button. If you want to add more TextBlocks or other Components, you will have to work with the style.
In this example, I created a negative margin on top, so the block could move up, aligned to the bar icon and close button.

Related

WPF Calculated FontSize Inside ViewBox

I have faced a problem and tried the internet and threads here to find a solution but haven't found yet.
I am a beginner in programming any help will be appreciated.
I have a window which will be displayed on the secondary screen and a TextBlock wrapped in a viewbox and the text is binded and will be populated dymnamically on runtime on the second screen. The fontsize is also Binded and can be changed by the user.
This is working perfectly well.
The Problem Is That when the user increases fontsize to a higher value the text looks good if the text is short but if the text is very very large the text looks ugly sometimes becomes unreadable.
I have tried the ViewBox's Sretch direction and stretch but haven't found a better way to solve my problem but manually if there is very very long text and the text is unreadable reducing the fontsize makes text readable.
How may i be helped. One solution I have in mind is to calculate the fontsize maybe on height and width of parent grid such that when the text is very long the calculation reduces the fontsize to where it becomes readable.
here is my sample Xaml
<Grid>
<Viewbox Stretch="Fill"
StretchDirection="DownOnly">
<TextBlock Text="{Binding}"
Width="{Binding}"
FontSize="{Binding}"
TextWrapping="Wrap">
</TextBlock>
</Viewbox>
</Grid>
Here is the Ugly Behavior when text is very long and fontsize is set highly
Expected behavior. Here the fontsize is manually set lower
Okay I found a work around the problem. If anyone has another solution it will be welcomed.
I wrapped the textblock inside a border and removed binding of the width of the textblock and I will be increasing and decreasing the width. If font size increases I will decrease the width by a ratio in the ViewModel and vice versa.
<Grid>
<Viewbox >
<Border>
<TextBlock Text="{Binding}"
Width="{Binding}"
FontSize="{Binding}"
TextWrapping="Wrap">
</TextBlock>
</Border>
</Viewbox>

how to make NoResize WPF window that is sized to it's content but wide enough to show title entirely? [duplicate]

If I have Window in WPF as follows:
<Window
Title="Alter Window Width so that the complete title is shown."
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner">
This window will automatically resize to make sure all of its content is visible. But it doesn't do the same for the title, so it's possible that a part of the title will be hidden when the window is shown.
What can be done to make sure that the width of the window is enough to show the title in the title bar?
Add a hidden textblock in to the window:
<TextBlock
Text="{Binding Path=Title,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
Visibility="Hidden"
Height="0"
Margin="100 0 0 0">
</TextBlock>
The Margin allows for the windows controls to be pushed out of the way.
The Height makes the control take up no vertical space.
The Visiblity is probable not required because of the zero height, but by setting it to hidden will cause it to take up space on the canvas but show nothing.

Multi-line padded text in WPF

I am trying to implement a rectangular shadow effect in WPF, something like this:
https://css-tricks.com/multi-line-padded-text/
The shadow should follow each line of text, but it should not have a space between the lines. Also, the shadow will have some transparency, and this rules out adding a separate background to inline Runs. I tried this, and where the shadows overlapped the opacity values formed a darker color.
I have investigated so far TextBox, TextBlock and RichTextBox. I tried changing Run.Background, or selecting the text and changing the selection foreground/background. With no success, none of these are doing exactly what I need.
Basically what (I think) I need is a text formatting feature, that would allow me to create a properly wrapped text from a string IN MEMORY, with separate Runs for each and every line. After this, I could find out the pixel length of each Run, add these Runs manually to a RichTextBox or to a TextBlock, with manually created rectangles behind them.
Unfortunately, when I add text to a TextBlock or a RichTextBox, wrapping is applied to the Run itself, instead of creating separate Runs for each wrapped line.
I have not received any replies, so I am trying to answer my own question.
My major problem with TextBlock was that if I added a slightly transparent background color to the inline Run objects, they formed a darker color as the lines overlapped slightly. To overcome this issue, I changed the Run background to non-transparent, and this way the 100% opacity values would not result in visibly overlapping lines. Then I changed the opacity of the whole TextBlock to 80% - and I got the result I expected.
Here is a sample xaml:
<TextBlock TextWrapping="Wrap" FontWeight="SemiBold" FontSize="23" FontFamily="Arial" TextBlock.LineHeight="24.65"
TextOptions.TextFormattingMode="Ideal" TextTrimming="CharacterEllipsis" LineStackingStrategy="BlockLineHeight" Opacity="0.8">
<Run Background="#FFFF0000" Text="This text here" />
<Run Background="#FFFF0000" Text="will be visible across" />
<Run Background="#FFFF0000" Text="multiple lines" />
</TextBlock>
Please note that the LineHeight value is slightly higher than the FontSize value. This makes sure that there will be no visible gaps between the lines.

Why is the image only partially visible inside my Button?

I am developing a Windows Store app and I've done this before, months ago, but all of a sudden, in this new app, I can't get the image to display inside the button (properly).
<Button x:Name="ShowView" Grid.Column="1" Width="32" Height="32" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,61,20,33">
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Image x:Name="ShowViewImage" Source="/Assets/ShowView.png" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</StackPanel>
</Button>
As you can see, the code is fine (unless things have changed drastically, which by the looks of it they haven't). So what gives? This is the only code I have so far in my XAML file other than the defauls that VS generates as it's a new Project.
P.S. I've also tried taking out the StackPanel and just having Button > Image, but this produces the same result.
So, when the BUtton displays at runtime, all I can see is a very tiny, 2pixels of the image (but the image is actually 32x32pixels. How do I properly display an "Image Button"?
The problem is that your Width and Height for the button are far too small. You've made it 32x32 pixels, but the button will use almost all of that itself for the space it leaves around the visible border, the border itself, and the padding between the border and the button's content.
(It leaves space around the edge to provide a larger hit target than the visible appearance. This is useful on touchscreens, where accurate finger placement is difficult.)
All that's left for your image is a few pixels.
You'll need to make the button about 62x52 pixels to leave enough space in the middle for a 32x32 pixel bitmap.
You could get away with a slightly smaller button if you explicitly set smaller Margin and Padding properties, although as mentioned above, the margin is there for a reason.
You have a couple options, the Padding property for instance is Template bound with some pre-set padding added to it. So with your Button having a fixed Height and Width set to 32 something as simple as setting Padding="0" could fix it for you depending on the actual size of your Image.
If worse comes to worse though, you could always just make your own Button Template. There's a couple easy ways to do this. One of which would be just go make a copy of the default Button Template, rip out all the Padding/Margin/Height/Width crap preset in there and just change its name then apply your new template directly to your button like;
<Button x:Name="ShowView" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,61,20,33"
Style="{StaticResource YourCustomButtonTemplateForImages}">
<Image x:Name="ShowViewImage" Source="/Assets/ShowView.png"/>
</Button>
Or... another option would be, embed your Image inside of a ViewBox inside your button and it will fit and re-scale itself accordingly to its set available size.
Oh, you might also want to make your Background="Transparent" while you're at it to make it look a little cleaner as just an image.
Hope this helps.

I'm using a WPF TextBlock but then text gets cut off when it's too long. Is there an AutoScroll feature?

My TextBlock has for example 50x50 pixels to display text, however if there is more text, I want a user to be able to scroll. Is there an autoscroll feature for this control?
Should I use a different control better suited for this task?
Here's a couple of pics to illustrate the problem:
This one works fine because the text fits in snugly:
This one doesn't seem correct. Text is cut off.
Just in case someone comes into the same problem. Just wrap the textBlock with a control. Works like a charm!
<ScrollViewer Background="Black">
<TextBlock x:Name="textBlockBackStory"
FontSize="12"
Foreground="Orange"
TextWrapping="Wrap"
Background="Black"
TextDecorations="None">
Backstory here.
</TextBlock>
</ScrollViewer>
You can put your textblock inside a ViewBox, so the font will adjust to display the entire text.

Categories

Resources