how fix the background color of a page independent of the theme in wp7? - xaml

I just want a particular page to be with white background color whatever may be the theme.
How can I do that?
Thanks in advance!

set Background of the layout root like this
<Grid x:Name="LayoutRoot" Background="Black">

If background disappears,
then create an event handler for TextBox_GotFocus.
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
var clickedUIElement = sender as TextBox;
clickedUIElement.BorderBrush = new SolidColorBrush(Colors.Black);
}

Related

How to add button to pivot header

I want to add a button to the pivot header so that it is shown in-line with pivot item titles, but doesn't update the content shown but just launches an event instead.
After some experimenting, I discovered how to do this. First place a button inside a PivotItem's header. Set it up to route tap events as well as click events.
<PivotItem>
<PivotItem.Header>
<Button
x:Name="MyButton"
Tapped="PivotItem_Tapped"
Click="MyButton_Click">MyButton</Button>
</PivotItem.Header>
</PivotItem>
Then inside the handler for the tap, consume the tap event. Clicking on the button won't update the pivot's content now:
private void MyButton_Click(object sender, RoutedEventArgs e)
{
//do whatever you need.
}
private void PivotItem_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
e.Handled = true;
}

UWP - Close my content dialog on click on the blank area

I have created a content dialog for my UWP app which involves a centralized UI Element and a surrounding blank area.But content dialog does not have a property like "IsLightDismissEnabled" to close the dialog on click on an area except the UIELEMENT area.How can I achieve it?
In the code behind your content dialog:
public sealed partial class CustomDialog : ContentDialog
{
public CustomDialog()
{
this.InitializeComponent();
Boolean isHide;
Window.Current.CoreWindow.PointerPressed += (s, e) =>
{
if (isHide)
Hide();
};
PointerExited += (s, e) => isHide = true;
PointerEntered += (s, e) => isHide = false;
}
}
There are few options that I can think of:
Use popup (like uruk suggested) and add your controls inside, create the popup at desired location (you could also use binding here if you want to show the popup at location depending on user input at runtime Popup has HorizontalOffset and VerticalOffset properties)
Create a parent view that is taking up the whole page but is transparent, then add your UI elements at the center and attach tap/click events to the transparent view. These events are going to just close remove/collapse the transparent view which contains the other elements inside (Either by binding of values or by setting the values to the UI elements).
Example or popup usage:
<Popup x:Name="MenuPopUp"
IsLightDismissEnabled="True"
HorizontalOffset="{Binding HorizontalOffset}"
VerticalOffset="{Binding VerticalOffset}"
IsOpen="{Binding IsOpen, Mode=TwoWay}">
<Grid>
YOUR ELEMENTS HERE
</Grid>
</Popup>
Content dialog is a modal dialog. Why don't you use a Popup or a child class of it? It's non-modal, and it already has the IsLightDismissEnabled property you just mentioned.
<Popup x:Name="MenuPopUp"
IsLightDismissEnabled="True"
LostFocus="MenuPopUp_LostFocus"/>
In CS
private void MenuPopUp_LostFocus(object sender, RoutedEventArgs e)
{
MenuPopup.IsOpen = false;
}

Change button background image when click in Windows Phone using XAML only?

So basically I want to have a button with a certain background image.
For example, when the app is loaded you would see a button with it's background image as image1.png and then when it is clicked you see image2.png as the background image. Then when you click again, the background image is switched back to image1.png.
Even though I have done this in C#, I want to do it in XAML because every time you click a button it automatically lights up according to the theme color, and the only way to get rid of that is via XAML.
Here is my code so fa:
<Button x:Name="Buttons" Content="" HorizontalAlignment="Left" Margin="155,0,0,69" BorderBrush="Transparent" Width="140" Click="Button_Click" Height="141" VerticalAlignment="Bottom">
<Button.Background>
<ImageBrush Stretch="Fill" ImageSource="/Assets/image1.png"/>
</Button.Background>
</Button>
Thanks in advance!
Try this,
http://visualstudiomagazine.com/articles/2013/02/15/customize-windows-phone-togglebutton.aspx
Here, the ToggleButton that ships with the SDK has been templated to add a clicked and unclicked image.
Alternate Solution with a checkbox:
Creating own toggle button in WP8?
VisualStudio 2017 "Blank App"
XAML
<Button x:Name="button" Content="Button1" HorizontalAlignment="Left" Margin="400,20,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1.258,-5" Click="Button_Click" Height="80" Width="80"/>
C# (Set the original image in the properties of the button: right-click -> Brush -> image)
private void Button1_Click(object sender, RoutedEventArgs e)
{
button1.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("ms-appx:/Images/timerg.png", UriKind.RelativeOrAbsolute)) };
}
or C#
private void Button1_Click(object sender, RoutedEventArgs e)
{
BitmapImage bmp = new BitmapImage();
Uri u = new Uri("ms-appx:/Images/timer.png", UriKind.RelativeOrAbsolute);
bmp.UriSource = u;
// NOTE: change starts here
Image i = new Image();
i.Source = bmp;
button1.Content = i;
}

How do I create a tap moveable control in WinRT?

I wrote a UserControl in WinRT and I want to make it moveable with a finger.
When I move it using a pen or mouse it is still moving but not when i use a finger.
The PointerMoved is not triggert when I use a finger.
Here is the simple xaml:
<UserControl>
<Rectangle PointerPressed="PointerPressed" PointerMoved="PointerMoved"/>
</UserControl>
and here is the code:
private Point position;
void PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
Rectangle r = sender as Rectangle;
var pointerPoint = e.GetCurrentPoint(r);
position = pointerPoint.Position;
}
void PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
Rectangle r = sender as Rectangle;
var delta = e.GetCurrentPoint(r).Position;
r.Margin = new Thickness(r.Margin.Left + delta.X - position.X, r.Margin.Top + delta.Y - position.Y, 0, 0);
}
What do I miss here?
Edit:
I am working with Windows 8.1 and VisualStudio 2013.
Maybe it's a new feature^^
It's simpler than you think!
<Rectangle Width="100" Height="100" Fill="White"
ManipulationMode="TranslateX,TranslateY"
ManipulationDelta="Rectangle_ManipulationDelta_1" />
private void Rectangle_ManipulationDelta_1(object sender, ManipulationDeltaRoutedEventArgs e)
{
var _Rectangle = sender as Windows.UI.Xaml.Shapes.Rectangle;
var _Transform = (_Rectangle.RenderTransform as CompositeTransform)
?? (_Rectangle.RenderTransform = new CompositeTransform()) as CompositeTransform;
_Transform.TranslateX += e.Delta.Translation.X;
_Transform.TranslateY += e.Delta.Translation.Y;
}
Best of luck!
First, don't sure you can move by pen or mouse because in PointerMoved event you should check the e.Pointer.IsInContact boolean value to ensure you are selected the object when moving. It make your moving action looks better.
Second, Sorry that I don't know why in your machine the PointerMoved is not triggered when uses finger. Anyway it will better if you set the name of your handler function not same as event name.
If you can share more information, we can discuss.

is it possible to change Button text color in c++ cx metro app?

I have the following XAML code
XAML:
<Button x:Name = "Btn1" Click = "Button_Click">
can i change the color of the font in the Button_Click method or anywhere else in code?
You can implement it by the following code runs in directX 2013:
void App2::DirectXPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) {
bt->Foreground = ref new SolidColorBrush(Windows::UI::Colors::Blue);
}
Yes you can change the color of the button any where in the code
Here's a sample button and a sample code to change color in it's click event
Heres the code to change the color in the click event of the btnChangeFontColor
private void Button_Click_1(object sender, RoutedEventArgs e)
{
btnChangeFontColor.Foreground = new SolidColorBrush(Colors.Red);
}