Windows Phone: How to remove TimeSpanPicker highlight on press? - windows-phone-8

I am using a TimeSpanPicker in my app. When I press it to select the time, the button background color will change to yellow.
for(int i=0;i< 3;i++)
{
TimeSpanPicker tsp = new TimeSpanPicker();
tsp.Value = TimeSpan.Parse("00:00:00");
tsp.Height=72;
Instance.Listbox1.Elements.Add(tsp); // something like this
}
How do I change the Style of the Windows Phone TimeSpanPicker control?

After two days of searching, finally I found how to change the background of a TimeSpanPicker.
Step 1 : Change Style of TimeSpanPicker in your xaml file. (in my case I wanted to change the background color to Transparent, so I set the value to Transparent)
<Grid x:Name="grid">
<Grid.Resources>
<Style x:Key="SampleStyle" TargetType="toolkit:TimeSpanPaicker">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="Yellow"/>
</Style>
</Grid.Resources>
</Grid>
Step 2: use the above style in code behind. You just need to set the style of a new TimeSpanPicker to the style on the top.
TimeSpanPicker tsp = new TimeSpanPicker();
tsp.Style = (System.Windows.Style)Resources["SampleStyle"];
That is how we can change different features of our TimeSpanPicker.

Related

How to change style code behind windows phone app 8.1 RT

I have a style in App.xaml like below
<Style TargetType="TextBlock" x:Key="Styletext">
<Setter Property="Fontsize" Value="13"/></Style>
And in the mainpage.xaml. I have
<TextBlock Content="ABC" Style={StaticResource Styletext/>
And 2 Button Aa-,Aa+ To Up size for that textblock. So Question is: How I can get Value from Property"Fontsize" and + or - it and Modify Style to Assign for TextBlock. Tks All
You can not change the style in static resource. For your requirement, you can considering setting the style of TextBlock in code behind.
For example:
var dynamicStyle = new Windows.UI.Xaml.Style();
var targetType = typeof(Windows.UI.Xaml.Controls.TextBlock);
dynamicStyle.TargetType = targetType;
dynamicStyle.Setters.Add(new Setter(Windows.UI.Xaml.Controls.TextBlock.FontSizeProperty, text01.FontSize + 1));
text01.Style = dynamicStyle;

change SystemTray Color in whole application - windows phone

I want to change the SystemTray Background and Foreground color in whole application but I don't define a base page and now I can't change the color for each page. is there a way for changing the background and foreground color of SystemTray in whole application through App.xaml.cs
Solution for Windows phone RT app:
In OnLaunched method of App.xaml add below code:
var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
statusBar.BackgroundColor = Colors.Green;
statusBar.ForegroundColor = Colors.Red;
statusBar.BackgroundOpacity = 1;
statusBar.ProgressIndicator.Text = "Some text";
statusBar.ProgressIndicator.ShowAsync();
Ref: http://blogs.msdn.com/b/amar/archive/2014/05/12/status-bar-in-windows-phone-8-1.aspx
For WP Silverlight App:
You may need to define style in App.xaml under tag
<Style x:Key="SystemTrayStyle" TargetType="phone:PhoneApplicationPage">
<Setter Property="shell:SystemTray.BackgroundColor" Value="Red" />
<Setter Property="shell:SystemTray.ForegroundColor" Value="Green" />
</Style>
And on individual xaml page you can add this style
<phone:PhoneApplicationPage
shell:SystemTray.IsVisible="True"
Style="{StaticResource SystemTrayStyle}">

Flipview VirtualizingStackPanel orientation change on WP8.1

I want to change the orientation property like the following below:
<Style x:Key="FlipViewStyleV" TargetType="FlipView">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel AreScrollSnapPointsRegular="True" Orientation="Vertical" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
And I want to let it worked when the device orientation changed, the orientation property should also follow the change. But it does not worked when I add a button in the code-behind to change the orientation from vertical to horizontal, does some one know?
Looks like changing the Orientation property of a FlipView's ItemsPanel doesn't work for some reason. So here's an alternative.
You will need to duplicate your FlipView. One would implement a Vertical VirtualizingStackPanel and the other a Horizontal VirtualizingStackPanel.
Define them in your page's Resources.
<Page.Resources>
<ItemsPanelTemplate x:Key="HorizontalItemsPanel">
<VirtualizingStackPanel AreScrollSnapPointsRegular="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="VerticalItemsPanel">
<VirtualizingStackPanel AreScrollSnapPointsRegular="True" Orientation="Vertical" />
</ItemsPanelTemplate>
</Page.Resources>
Then, you will want to use SimpleOrientationSensor to monitor the phone's orientation changes.
private SimpleOrientationSensor _orientationSensor = SimpleOrientationSensor.GetDefault();
After you have subscribed to its OrientationChanged event,
_orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged;
in its callback, simply hide and show the FlipViews accordingly.
private async void OrientationSensor_OrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
switch (args.Orientation)
{
case SimpleOrientation.NotRotated:
case SimpleOrientation.Rotated180DegreesCounterclockwise:
this.HorizontalFlipView.Visibility = Visibility.Visible;
this.VerticalFlipView.Visibility = Visibility.Collapsed;
break;
case SimpleOrientation.Rotated90DegreesCounterclockwise:
case SimpleOrientation.Rotated270DegreesCounterclockwise:
this.HorizontalFlipView.Visibility = Visibility.Collapsed;
this.VerticalFlipView.Visibility = Visibility.Visible;
break;
}
});
}

Pivot Item Header Coulor Change opacity of all Headers Remains Same in windows Phone 8.1 Pivot Control

I am working on Pivot Control in Windows Phone 8.1 I Set foreground Property of pivotitem Header to Red Color it is working Fine but,I set all items header to Red Color and the Opacity of the Item Header Never Changes of UnFocused PivotItem cloud Please Help me how to solve this
Problem.
Here is the code
<Pivot Title="Pivot Title" >
<PivotItem >
<PivotItem.Header >
<TextBlock Text="One" Foreground="Red" FontSize="48"/>
</PivotItem.Header>
</PivotItem>
<PivotItem>
<PivotItem.Header>
<TextBlock Text="two" Foreground="Red" FontSize="48"/>
</PivotItem.Header>
</PivotItem>
<PivotItem>
<PivotItem.Header>
<TextBlock Text="three" Foreground="Red" FontSize="48"/>
</PivotItem.Header>
</PivotItem>
</Pivot>
The Default Styles Should be over ridden in Resource Dictionary <ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="PivotHeaderForegroundUnselectedBrush" Color="#AFAFAF" />
<SolidColorBrush x:Key="PivotHeaderForegroundSelectedBrush" Color="#56C5FF" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
I guess you'll need to set a different VisualState for either the Selected or Unselected state.
Have a look over here How to Change Pivot Header Template in Windows Phone 8
Or you could use the SelectionChanged event handler for your pivot:
private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
PivotItem currentItem = e.AddedItems[0] as PivotItem;
if (currentItem != null)
{
(currentItem.Header as TextBlock).Foreground = new SolidColorBrush(Colors.White);
}
}
if (e.RemovedItems.Count > 0)
{
PivotItem currentItem = e.RemovedItems[0] as PivotItem;
if (currentItem != null)
{
(currentItem.Header as TextBlock).Foreground = new SolidColorBrush(Colors.Red);
}
}
}
Hope it helps!

Disabling keyboard of windows phone having focus on Textbox

I am new in Windows Phone.
In my app I have a textbox where cursor will continuously blink for input at first. I have a custom dialpad to take input from users. So I have to disable the Windows Phone Keyboard.
After searching online, most of the solution is based on removing the focus from textbox to hide the keyboard.
In my case, its not happening since keyboard pops up and hide instantly.
Any help would be highly appreciated.
Another thing: I also need the cursor to be blinking in textbox.
May this will help you, create GotFocus event of your textbox.
GotFocus="input_GotFocus"
private void input_GotFocus(object sender, RoutedEventArgs e)
{
this.Focus();
}
One workaround could be to not use TextBox at all. Instead, you can use a simple TextBlock and on tap on the TextBlock, open your custom keypad. You can probably toggle visibility of the keypad to hide/unhide it. on key press of the keypad, update the text of the TextBlock.
EDIT : Adding a sample code for this (with cursor implementation as well)
Xaml for my custom TextBox implementation :
<Border x:Name="brdTextBox" Background="White" BorderBrush="Blue" HorizontalAlignment="Stretch" Height="100"
Margin="10">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="txtEnterText" FontSize="28" Foreground="Black" Margin="0"></TextBlock>
<TextBlock x:Name="txtCursor" FontSize="28" Foreground="Black" Text="|" Margin="0"></TextBlock>
</StackPanel>
</Border>
A sample code behind, that uses timer to control the tick of the cursor :
Timer timer = new Timer((obj) =>
{
Dispatcher pageDispatcher = obj as Dispatcher;
pageDispatcher.BeginInvoke(() =>
{
if (txtCursor.Text == "|")
{
txtCursor.Text = "";
}
else
{
txtCursor.Text = "|";
}
});
}, this.Dispatcher, 1000, 1000);
After this, you can probably bring up your keypad on border tap, and on key event of the keypad, fill up the textblock. You can tweak the timer duration and intervals to achieve a close resemblance to the actual cursor.
Hope it helps.