Check foreground color of textblock - windows-phone-7

I want to check my foreground color of my tapped textblock..
The code I have used is
If(textblock.foreground.equals(system.media.color.fromargb(100,0,255,0)))
Messagebox.show("got it ")";
This code is not working can any one help me??
Edited :- I want to check the color of 4 textblock.. I know the index value of the the textblock..

Try this:
private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
if(((sender as TextBlock).Foreground as SolidColorBrush).Color.Equals(Colors.Green))
{
MessageBox.Show("It is green");
}
}

Related

How to change uwp app title bar color when Windows 10 change from dark theme to light and vice versa?

I have an app for test, with 3 buttons:
one for change title bar color to white
one for change title bar color to black
one for let the app title bar free to follow the Windows 10 theme color for its app title bar
Those first two buttons are ok and working, but the last one I don't know how to implement and where to put methods if necessary. I'd like, please, any help, tip or even a whole solution for the problem. Thank you in advance.
PS: would be great if title bar color can follow dark, light and even high contrast colors.
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App7
{
public sealed partial class MainPage : Page
{
Windows.UI.ViewManagement.ApplicationViewTitleBar titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;
public MainPage()
{
this.InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
titleBar.BackgroundColor = Windows.UI.Colors.White;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
titleBar.BackgroundColor = Windows.UI.Colors.Black;
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
//Title bar must be free to change its own colour accord/when/same time Windows theme change
//How can I do that?
//Where the code/methods goes?
}
}
}
You could handle the ColorValuesChanged Event of the UISettings Class. This event will happen when the Windows theme color is changed. You could get the current color of the Windows theme using UISettings.GetColorValue() to check if it is in Dark mode or Light mode. Then you could change the title bar color as you want.
Here is the code:
public Windows.UI.ViewManagement.UISettings uiSettings { get; set; }
private void Button_Click(object sender, RoutedEventArgs e)
{
uiSettings = new Windows.UI.ViewManagement.UISettings();
uiSettings.ColorValuesChanged += UiSettings_ColorValuesChanged;
// if you want to stop this.
//uiSettings.ColorValuesChanged -= UiSettings_ColorValuesChanged;
}
private void UiSettings_ColorValuesChanged(Windows.UI.ViewManagement.UISettings sender, object args)
{
// happens when the windows theme is changed.
// The color you get is either black(#FF000000) for dark theme or white(#FFFFFFFF) for light theme.
Color backgroundcolor = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background);
// change titlebar color.
Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar.BackgroundColor = backgroundcolor;
}

Change BoxView color on Tap

I have a BoxView that I want to change the color of when the user taps it. I created a BoxView called tapView and set the GestureRecognizer like so:
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) => {
// handle the tap
OnTapGestureRecognizerTapped(s, e);
};
tapView.GestureRecognizers.Add(tapGestureRecognizer);
and my method to handle the tap:
void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{
var box = (BoxView)sender;
box.Color = Color.Red;
}
However this doesn't actually change the color on the Tap. Debugging and stepping through the code it does actually update the BoxView color in the code but not on the screen. What do I need to do to make this actually update the color when touched?
Try this solution, assuming you give your BoxView the following property in your XAML x:Name="myBox"
//This code betlow the page InitializeComponent call
var boxTapHandler = new TapGestureRecognizer();
boxTapHandler.Tapped += ChangeColor;
myBox.GestureRecognizers.Add(boxTapHandler);
Change color method, similar, though referencing the BoxView by name
private void ChangeColor(object sender, EventArgs args)
{
myBox.Color = Color.red;
}
So I discovered as standalone code this works ok, but in my MVVM app it does not. I wound up creating a box on top and changing the opacity on a tap worked just fine.

Xamarin.Forms: How to Give Highlight Color to Label On Tap?

I know that I can make a Label clickable by using TapGesture. How can I give a highlight effect when the user is tapping it? (Either changing the Label's color or changing the Background Color just like when the user taps the Toolbar Items)
You could simulate the effect with a TapGestureRecognizer by just changing the color of your label in your tapped method and back at the end.
private void OnTapped(object sender, EventArgs e)
{
var label = sender as Label;
label.TextColor = Color.Gray;
//Do Something
label.TextColor = Color.Black;
}
Although, styling a button might work better to handle the effect for you.
Here is a fix to Nick Pepper's answer, to properly restore color on UI thread.
private void OnTapped(object sender, EventArgs e)
{
var label = sender as Label;
label.TextColor = Color.Gray;
Run.Task( () => {
// Now we are on a background thread, can take as long as we want.
// ... Do Something ...
Device.BeginInvokeOnMainThread( () => {
// Now we are back on main thread, can change UI.
label.TextColor = Color.Black;
});
});
}
HOWEVER this won't change color to Gray until OnTapped fires - which is NOT the instant that user pushes down. So still isn't what user asked for.
Changing the color as soon as the user starts pushing is more involved. Might need to use Touch Tracking API.
OR use Visual State Manager.

set RowElement.BackColor in Telerik RadGridView (WinForms) in RowFormatting event

Is there some trick to setting the back color of the row in the Telerik WinForms RadGridView at runtime in the RowFormatting event? I am able to set the RowElement.Font in this event but not the RowElement.BackColor. I have stepped through the code in the debugger and am certain that the line is being executed (the event is properly "wired up").
void grid_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
{
if (e.RowElement.RowInfo.Cells["CODE"].Value.ToString() == "X"))
{
// the following line is executed but has no apparent effect
e.RowElement.BackColor = System.Drawing.Color.Aqua;
}
}
Your code looks good, you just need to set DrawFill to true
Add this:
e.RowElement.DrawFill = true;
Full example:
void grid_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
{
if (e.RowElement.RowInfo.Cells["CODE"].Value.ToString() == "X"))
{
e.RowElement.DrawFill = true;
e.RowElement.BackColor = System.Drawing.Color.Aqua;
}
}

MouseClick on Label

I am trying to register a click on a label, but i can't get it to work.
So far I've tried to set the SelectionAdapter to the label but click-events aren't fired.
Labels are not selectable Controls SelectionAdapter won't work for it. Try adding a MouseListener.
For sake of completeness, I'll just add this code sample:
label.addMouseListener(new MouseAdapter() {
#Override
public void mouseUp(MouseEvent event) {
super.mouseUp(event);
if (event.getSource() instanceof Label) {
Label label = (Label)event.getSource();
System.out.println("Label was clicked: " + label.getText());
}
}
});

Resources