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;
Related
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}">
In WP8.1 project I created MapIcon and added it in MapElements. In some levels of zoom image is drawen but sometimes when I zoom in or zoom out it disappears (I thin when place names are to close to image). How is this possible to fix? Thanks in advance!
Code behind
mapIcon = new MapIcon();
mapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
mapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/mapIcon.png"));
mapIcon.Title = "You are here!";
MyMapControl.MapElements.Add(mapIcon);
mapIcon.Location = new Geopoint(new BasicGeoposition()
{
Latitude = geoLoc.Latitude,
Longitude = geoLoc.Longitude
});
XAML
<Grid Grid.Row="0" x:Name="ContentRoot" Margin="0,0,0,0">
<Maps:MapControl
x:Name="MyMapControl"
MapServiceToken="<my token>"
ZoomLevel="13.5"
LandmarksVisible="True"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0,0,0,0"
>
</Maps:MapControl>
</Grid>
MapIcon elements are not guaranteed to be shown, they may be obscured by other elements, or if they are too close.
If you want to have a control that always shows, then use a XAML element: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn792121.aspx#showing_xaml_controls_and_shapes_on_the_map
I need to use ttf for some icons in my Win8 phone project. I did a research but couldn't find any resources. Is there a way to achieve this?
<TextBlock x:Name="textBlock" Text="\uE82E" FontFamily="/fontello.ttf#fontello" />
Custom Font Runtime
TextBlock t = new TextBlock();
FontFamily ff = new FontFamily("/Fonts/fontello.ttf#fontello");
t.FontFamily = ff;
t.Text = "";
You can specify the Unicode value in this way:
XAML:
<TextBlock x:Name="textBlock" Text="" FontFamily="fontello.ttf#fontello" />
Code behind:
textBlock.FontFamily = new FontFamily("fontello.ttf#fontello");
textBlock.Text = "\uE82E";
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!
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.