I'm attempting to extend a RichTextBox, so as to add some extra functionality; however, I'm running into a strange issue with the background color of my extended RTB. Here is the code:
RichTextBoxExtended.cs
public class RichTextBoxExtended: RichTextBox
{
// completely empty
}
MyView.xaml
<UserControl x:Class="MyNamespace.MyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<RichTextBoxExtended />
</Grid>
</UserControl>
However, when showing this in a WPF page, the background color of the text box is gray, as if it were disabled (which it isn't, since I can still type into it fine). As a test, I replaced <RichTextBoxExtended /> in the XAML with <RichTextBox />, and that control is white as expected.
Does anyone know what could cause this issue? I can easily work around the problem by manually setting the background color to white, but am looking for a better solution.
I just copy paste your code to a test solution, place a frame in main window and put the RichTextBoxExtended in a page inside the frame, but the background of RTB is completely white. I think there is something else causing the problem.
Related
I'd like to have some sort of semi transparent/translucent effect displayed over the entire page and then display my option buttons on top of it but I just can't figure out how and it's driving me nuts! I've seen it in plenty of wp8 apps so it is doable but I just don't know how!
Once this semi transparent/translucent effect is displayed, I want it to dissapeared if clicked on or if one of my option buttons is clicked, and restore the screen as it was or execute an action accordingly.
I've somehow managed to do it by setting the Background colors using a storyboard but strangely enough, once displayed and my options buttons appear, they look fine but once the storyboard is completed, the button then look disabled as well which just looks wrong!!
What is the proper way to give a "Disabled" effect as if you had a semi transparent dialog box displayed over a window.
Any ideas, suggestions or code would be appreciated.
Thanks.
You may be making this more complicated than it needs to be. Consider the following XAML for example:
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="ContentRoot">
...
</Grid>
<Grid x:Name="ContentOverlay" Background="#AA000000" Visibility="Collapsed">
...
</Grid>
</Grid>
Both ContentRoot and ContentOverlay will anchor at the top left of the LayoutRoot grid and span the row height. They will stack from furthest to closest in order of declaration, so ContentRoot will be rendered beneath ContentOverlay. Simply manipulate the Visibility of ContentOverlay based on user input.
Alternatively, you can set the Opacity for ContentOverlay to 0 along with collapsed visibility (required so it doesn't intercept hits to the ContentRoot child controls below) and fade it in and out using storyboarding in Blend. That probably looks like a slightly cleaner transition to a user, even if it's only 0.3 seconds long or so.
Use Blend to specify VisualStates (View | States. Then 'states' tab.) You can switch between states in code behind using VisualStateManager.GoToState. One state would be normal, the other all controls disabled.
Mike
I have UserControl in SL4 project with a richtextbox with big amount of text in it. Problem that mouse scrolling doesn't work in it. While I dragging scroll bar - that works and when I press arrows on keyboard - scroll is working too, but when I am trying to use mouse wheel for scrolling - it doesnt work at all.
I've reduced this control to simplest:
<UserControl x:Class="CTermsOfUsePage"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="900">
<RichTextBox Height="400">
<Paragraph>
Big amount of text with many LineBreaks here.
</Paragraph>
</RichTextBox>
</UserControl>
But the scroll still doesn't work. I've tried to create a new SL application with such code - all is working fine there. I've also checked default styles - there is no style for RichTextBox.
Are there any suggestion - what can be a problem's source?
Update: problem occur in Chrome/FF/Opera in IE9 scroll is working fine.
We've found problem source. In project's .aspx file in <div id="silverlightControlHost"> section we have a setting <param name="windowless" value="true" />. When this parameter has been set to false all worked fine.
As well as in IE "true" settings works fine it looks like SL bug.
I have a Popup that consists of a grid of labels. The popup sits inside a Canvas like this.
<Canvas x:Name="mainCanvas">
<Popup x:Name="mainPopup"
IsOpen="True"
PlacementTarget="{Binding ElementName=mainCanvas}"
PopupAnimation="Fade"
AllowsTransparency="True"
Placement="Center">
Wrapping inside the canvas (or similar control) is the only way I've found to allow the popup's contents to be transparent.
Anyway, all of this works fine and I see my grid of labels across the center of the screen. What I'd really want though is to display the grid of labels across the bottom of the screen. However when I change Placement="Center" to Placement="Bottom", I don't see the popup at all.
Have you seen this? It is a pretty good explanation about how popup placement works.
I created a test WPF project in Blend and pasted your exact code, then changed Placement to Bottom. I did see the content I added to the popup (a TextBlock with some junk text), but it was hard to see, since it is positioned below mainCanvas (as expected).
So... there must be some other problem aside from the code you showed.
I'm trying to play around with colors in WPF and the form's background color. Without doing ANYTHING ELSE (no code behind, deriving from another class, etc), I create a brand new default Windows Form. I change the background to some light blue color. Save the form. Run the program and open that form.. The form shows up in some other much darker color like it's not even respecting the XAML of
<Window x:Class="MyProjectNamespace.AnotherWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AnotherWindow" Height="300" Width="300" Background="#4800A8A6">
<Grid>
</Grid>
</Window>
Additionally, if I try to take this same background value of #4800A8A6 and try to create a brush and do a BrushConverter.ConvertFrom( "#4800A8A6" );
and run the form, I STILL get the incorrect color as displayed via the designer... what gives...
The first byte of your color code, the '48' is an alpha value, so you're allowing alpha blending on your Window (not a "Windows Form" btw, that's a different technology ;) ), which means the color of your window is going to be blended with the colors of things behind it.
Try changing to: #FF00A8A6, see if that gives you a better result.
Your problem is the inclusion of an Alpha channel in the background color (i.e. #AARRGGBB). In the designer you're seeing the background being composited against whatever the background color is in VS (in my case White), which will "lighten" the background in comparison to when you run it as standalone.
To see this for yourself, try Background="#00A8A6", or you could try adding AllowsTransparency="True" (but this has an onerous requirement of WindowStyle.None).
That's probably because of the alpha component in your color. If you are trying to make your windows transparent, you have to use AllowsTransparency="True". If you don't, WPF will merge the default windows background color with your windows background.
this may be a pretty simple question.
I've created a VS Package and it has a nice little GUI. The background of the GUI should be System.Colors.ControlBrush:
<Grid Background="{x:Static SystemColors.ControlBrush}">
Now I have the problem, that it changes the color of the Grid, but not of the rest of the window. -> Screenshot
I thought I could change the background of the UserControl the same way, but somehow it doesn't work. Now it doesn't really look that great, if a part of the window is grey and the rest is white.
Any idea?
Your UserControl is probably not covering the entire window.
Remove any Width or Height attributes and make sure that the Horizontal/Vertical Alignments are both Stretch.