First of all, my case is in UWP apps.
TextBlock has a property named SelectionHighlightColor that allows you specify the concrete color of the Selection Area when you select a text. Just like this:
XAML:
<TextBlock Text="This is a sample text" IsTextSelectionEnabled="True" SelectionHighlightColor="#FFFFE751" Foreground="Black" />
That displays as:
In case you haven't notice, the foreground of selected text is always White even the background of selection area is of light color.
So is there any way to change the foreground of Selected text of TextBlock control?
Related
I am creating a UWP application and I want a simple check box, no text, for each entry in my ListView. If I add a checkbox control to my template for the listview, I get a big gap after the checkbox for the Content - event when the content is empty.
If I turn on multiselect in the listview so I get a nice checkbox for each row, I can't seem to figure out how to databind the check box for each row in the listview to the Selected property of my ViewModel.
Below is a picture of what I want the area of the check box to look like. This was generated using the SelectionMode="Multiple" on the listview. Remember - the problem with this approach is I can't seem to find a way to bind the check box to the Selected property of my ViewModel class.
Below is what it looks like if I remove the SeletionMode property and add a check box to my ItemTemplate. As you can see there is a huge gap between the check box and the area where the image will be due to the Checkbox control's minimum width of 120.
Any suggestions would be greatly appreciated.
You could just set the MinWidth on the Checkbox itself
eg
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="MyCheck" IsChecked="True" MinWidth="30"/>
<Rectangle Fill="Red" Width="100" Height="50"/>
</StackPanel>
The alternative is creating a copy of the Checkbox Styles and Template but that seems like overkill here.
I have been trying to customize the Background color of ScrollBar in Windows Stores Apps. But its not working. I have a doubt whether is it a limitation in WinRT?
Thanks in Advance.
My Code Snippet:
If you want to change the Background color of the ScrollBar, you need to change the default style of the Scrollbar and the Blend for Visual Studio can help you implement it very easily.
For how to changing the style of the Scrollbar, please first please right-click the Scrollbar control-->click "Edit Template"-->"Edit a Copy", after that you will see all the style which creates the Scrollbar, then please find the following xaml and change the "Fill" property of the "Rectangle" with the Background color which you want, in this way it will change the Background color of the ScrollBar:
<Rectangle Fill="Yellow" Margin="0" Grid.RowSpan="5" Stroke="{ThemeResource ScrollBarTrackBorderThemeBrush}" StrokeThickness="{ThemeResource ScrollBarTrackBorderThemeThickness}"/>
We have put a scroll viewer inside a content panel in design page of a databound app. We have to add more number of textblocks inside the scrollviewer which we cannot do by dragging and dropping from the toolbar as the design shows only three textblocks...
You can add the textboxes manually and specify it's margin. You don't need to drag and drop. For example:
<Grid x:Name="Content Panel">
<ScrollViewer>
<TextBox x:Name="textbox_1" Margin="10,0,0,0"/>
<TextBox x:Name="textbox_2" Margin="10,10,0,0"/>
<TextBox x:Name="textbox_3" Margin="10,20,0,0"/>
<TextBox x:Name="textbox_4" Margin="10,30,0,0"/>
..and so on.
Margin parameters are Left, Top, Right and Bottom. Keep increasing the top margin to push the control below.
I need to prevent the TextBlock from changing the color of special characters, it looks like the WP TextBlock recognizes some shapes as emojis and colors them but it seems there is no way to control it like in Windows 8 like this article says:
http://blogs.windows.com/windows/b/appbuilder/archive/2013/11/11/xaml-text-improvements-in-windows-8-1.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.textbox.iscolorfontenabled.aspx
There is no IsColorFontEnabled in WP, anyone knows how to override this behavior?
The problem is with the heart character ♥, and I would not want to use a list of heart shape paths
EDIT: I have used the ❤ character but has different spacing and coloring than the normal one, I think the only way is to use a list of paths with this shape :(
Thanks
You can make the RichTextBox act like the TextBlock by setting the IsReadOnly property to true. It looks similar to the TextBlock, while the TextBox doesn't.
I'm not sure if you can control the emoji problem with this idea, you'd have to test, but it does allow you have full control over the color of text.
XAML
<StackPanel x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0">
<!-- One Color-->
<RichTextBox Foreground='White'>
<Paragraph>Text with ☻</Paragraph>
</RichTextBox>
<!-- Multi color -->
<RichTextBox IsReadOnly='True'>
<Paragraph>
<Run>Mixed Colors.</Run>
<Run Foreground='Red'
FontWeight='Bold'>☺</Run>
<Run Foreground='Yellow'>☻</Run>
<Run Foreground='LightGreen'>♫</Run>
</Paragraph>
</RichTextBox>
</StackPanel>
Output
I have a custom WPF control to display a list of items using an ItemsControl. The ItemsPresenter is defined in the template to display the list and it is embedded inside a ScrollViewer for scrolling purposes:
<ControlTemplate TargetType="ItemsControl">
<Grid x:Name="LayoutRoot">
<ScrollViewer Margin="3">
<ItemsPresenter/>
</ScrollViewer>
</Grid>
</ControlTemplate>
My application creates two instances of the custom control to show the list side by side.
What I want is when user selects an item on the first one, the second control automatically scrolls so that the same item is displayed in the same position relative to the top. To accomplish this I need to know
How to get the position (in pixels) of the selected item in the first control?
How to scroll to the same position in the second control?
Are there any other ways to do this?