I am developing the mapping functionality of our WP7 application. currently the pushpins appear as a circle graphic.
I am trying to create functionality to allow the user to be able to change the size of the circle of the pushpin, by sliding a bar. The idea being that the user can change the size of the pushpin anywhere between two sizes.
Therefore I don't want to create 2 or 3 pre-defined pushpin templates in XAML, and simply swap between them - I want to be able to modify an attribute of the template (specifically the height and width of the ellipse) in real time as the user slides a bar, or holds down on the page, or whatever.
However, I have been struggling to do this.
Is it possible to edit an attribute of an existing template? I have looked into creating a template in real time but this does not appear to be the solution, either.
Depending on the customer, the amount of pushpins that will appear on the page could vary by quite an amount. Also, our customers are outdoor types, and many struggle with smaller icons, whereas others don't. Hence my desire for this functionality.
Please find the XAML below, I simply wish to alter the size of the ellipse at run time. Thanks in advance for any help.
<ControlTemplate x:Key="PushpinControlTemplate1" TargetType="my:Pushpin">
<Grid x:Name="ContentGrid" Width="50" Height="50" >
<StackPanel Orientation="Vertical" >
<Grid MinHeight="31" MinWidth="29" Margin="0">
<Ellipse Fill="#FFFF7F00"
Margin="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="50"
Height="50"
Stroke="White"
StrokeThickness="3"/>
<ContentPresenter HorizontalAlignment="Center"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Margin="4"/>
</Grid>
</StackPanel>
</Grid>
</ControlTemplate>
Bind a Height property to the ViewModel's propetry.
<Ellipse
Width="50"
Height="{Binding ItemHeight}"/>
And change the property, when user slides the bar.
private DataTemplate CreateDataTemplate()
{
string xaml =
#"<DataTemplate
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Grid>
<Rectangle Fill=""LightGreen"" Height=""50"" Width=""250"" />
<TextBlock Text='{Binding}' FontSize='40' />
</Grid>
</DataTemplate>";
DataTemplate dt = (DataTemplate)XamlReader.Load(xaml);
return dt;
}
you can refer above code...
Click
.................................................................
binding your property
Related
In windows phone i could easily marquee a textblock. But is there any solution to marquee list of items for which i can define template and bind it to a list of items.
Thanks
Gokoulane Ravi
Although it's not a WP style...
Add storyboard to page resources:
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="Scroll" RepeatBehavior="Forever">
<DoubleAnimation From="480" To="-480" Storyboard.TargetName="translate" Storyboard.TargetProperty="X" Duration="0:0:5" />
</Storyboard>
</phone:PhoneApplicationPage.Resources>
Add ScrollViewer, add StackPanel inside and TextBlock inside:
<ScrollViewer x:Name="LongScrollViewer" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden" Margin="0,212,0,339" IsEnabled="False" >
<StackPanel Margin="0" Height="58">
<TextBlock x:Name="LongTextBlock" Text="Very long, real long, it's a long text." Margin="0" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Top"
HorizontalAlignment="Center" TextAlignment="Center" TextTrimming="None" TextWrapping="NoWrap">
<TextBlock.RenderTransform>
<TranslateTransform x:Name="translate" />
</TextBlock.RenderTransform>
</TextBlock>
</StackPanel>
</ScrollViewer>
In page's Loaded method make sure TextBlock's text is long enough for scrolling:
Size size = new Size(double.PositiveInfinity, double.PositiveInfinity);
this.LongTextBlock.Measure(size);
size = this.LongTextBlock.DesiredSize;
if (size.Width > this.ActualWidth)
{
this.Scroll.Begin();
}
You can do that. However you'll need to write custom XAML to achieve this functionality. Blend can help you over here to create that custom animation and run as marquee.
I need to display pop ups in my app. So I have user controls to make customised pop ups. Every pop up shows a different message and different set of buttons. Can I reuse the same xaml to alter the text and make new buttons? Or do I have to create seperate usercontrols?
<Grid Height="250" Width="480">
<Canvas Margin="0,0,0,0">
<Canvas.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF121111" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
<Button Content="Buy" x:Name="buttonBuy" Click="btnBuyNow_Click" BorderThickness="0" Style="{StaticResource UserControlBuy}" MinWidth="96" MinHeight="98" FontFamily="{StaticResource CicleFina}" FontSize="18.667" Canvas.Left="189" Canvas.Top="141" Height="98" Width="96" Foreground="#FF0E0C0C">
<Button.Background>
<ImageBrush ImageSource="Images/02/but_bg_trial_buy.png"/>
</Button.Background>
</Button>
<TextBlock TextWrapping="Wrap" FontSize="21.333" Padding="10" Text="Your trial period is over. Please purchase the full version" Height="141" Width="479" Foreground="#D48394" FontFamily="{StaticResource PeaSnow}" TextAlignment="Center" d:LayoutOverrides="Width, Height"/>
</Canvas>
</Grid>
This is how i've called the pop up in the app. .
Popup popup = new Popup();
BuyNowUserControl content = new BuyNowUserControl(popup);
// set the width of the popup to the width of the screen
content.Width = System.Windows.Application.Current.Host.Content.ActualWidth;
popup.Child = content;
popup.VerticalOffset = 300;
popup.IsOpen = true;
Thanks
Alfah
Yes, you can re-use them. I would do the following:
Create dependency properties on your user control for the customizable text you require.
Set the UserControl's DataContext to itself
Replace your hard-coded text in the above XAML with a binding to the dependency property added in (1)
You can now set the text on the user control instance after you have created it. The binding will ensure that the UI reflects this.
It is actually quite a bit of work to achieve this, so worth evaluating the benefit.
I would like to set the background color of the title of a panorama. I have done this by creating a DataTemplate and setting it to the TitleTemplate. I then set the background color as such:
<DataTemplate x:Key="PanoramaTitleTemplate">
<Grid Margin="0,50,0,0" Background="{StaticResource PhoneAccentBrush}">
<TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="133.333" />
</Grid>
</DataTemplate>
The problem is that on the last page of the panorama, the color doesn't fill the whole area. It ends where the text ends. I've tried setting the grid to a longer width, but not only does that still not fill the screen, it affects the title scrolling as well.
Create a DataTemplate for your Panorama Title and set the width of the TextBlock (items * 480):
<DataTemplate x:Key="PanoramaTitleTemplate">
<StackPanel Orientation="Horizontal" Background="#FF990000" Margin="-10 76 0 -9"> <!-- default 10,-76,0,9 -->
<Image x:Name="logoImage" Source="/ApplicationIcon.png" Margin="10 0 30 0" />
<TextBlock Text="{Binding}" VerticalAlignment="Center" Width="1920" Height="40" FontSize="20"/>
</StackPanel>
</DataTemplate>
This is due to the way the title is animated as part of the paralax effect.
You could write your own Panorama replacements but you'll find it much easier to add a separate image to the page instead of to the Panorama and add another item (probably a rectangle) in front of that which you can se to be the accent colour.
I have a working pivotviewer with 128 images of cars that I put together myself. I used one of the many tutorials on the web to get it working, and it works well. Then I thought I should decorate the page a bit so I put the grid in which the pv resided inside a bounding stackpanel with a couple of textblocks above it to tell what the collection is. Everything loads fine except the images. Comment out the stackpanel lines and it works perfectly.
Any ideas? How could something so simple fail?
Here is all of the code in MainPage.xaml:
<StackPanel>
<TextBlock
FontSize="24"
HorizontalAlignment="Center"
VerticalAlignment="Top">
Silverlight Pivotviewer Example
</TextBlock>
<TextBlock
FontSize="16"
HorizontalAlignment="Center"
VerticalAlignment="top">
Cool Automobiles
</TextBlock>
<Grid x:Name="LayoutRoot" Background="White">
<pivoter:PivotViewer x:Name="pivotViewer" />
</Grid>
</StackPanel>
Your Grid, "LayoutRoot", is your main layout control. You need to wrap your StackPanel within the Grid control.
Something like this:
<Grid x:Name="LayoutRoot" Background="White"
<StackPanel>
<TextBlock
FontSize="24"
HorizontalAlignment="Center"
VerticalAlignment="Top">
Silverlight Pivotviewer Example />
<TextBlock
FontSize="16"
HorizontalAlignment="Center"
VerticalAlignment="top">
Cool Automobiles />
<pivoter:PivotViewer x:Name="pivotViewer" />
</StackPanel>
</Grid>
After your declaration of your Grid, I would add some rows, i.e. 0, 1, 2. Then I would layout your Stackpanels, PivotViewer, etc.
Hope this helps.
This is a known issue. The StackPanel is a dimensionless element. You need to add Width and Height values to the StackPanel and the PivotViewer will begin working correctly.
This is what we did. We added an event handler to the SizeChanged event on the dialog then sized the PivotViewer. Also after the Initialise or Loaded event call it too...see how you go?
void PivotDialog_SizeChanged( object sender, SizeChangedEventArgs e )
{
SizePivotViewer( );
m_PivotViewer.UpdateLayout( );
}
private void SizePivotViewer( )
{
m_PivotViewer.Width = ActualWidth;
m_PivotViewer.Height = ActualHeight - 20; // Magic number so text will display properly at bottom of Pivot!
}
In a listbox I have a list of titles with an edit icon next to each, how do I increase the touchable area so that even if the user touches part of the title, it actually triggers the image event?
I assume I need to wrap the image in another element but cannot work out what that needs to be.
I tried wrapping the image in a button and add padding to the button but then it pushed the UI elements around, I do not want to affect the presentation, just the none-visible touchable area.
Wrap it in a button - you're totally in the right ball-park. But you need to edit the control template of the button and reduce down all the standard padding and margin, borders etc. so its just a raw touchable region.
You can then wrap anything in this button and apply your template/style to make anything interactive.
Luke
You could try wrapping in a Panel or Grid.
Or just adjust the margin and Z-Order.
Put the image in a button, set the size of the button you want & then set the Stroke property to "No brush" on the button to remove the border.
Try it:
<Border BorderBrush="Transparent"
BorderThickness="20,25,20,0"
Background="Transparent">
<Grid/>
</Border>
or use it in other variations:
<Border Background="Transparent">
<Grid Margin="20 25 20 0"/>
</Border>
full sample with button: (no background interaction when pressed at this sample)
<Button BorderBrush="Transparent"
Tag="{Binding SelectedPhoto.commentsCount}">
<Button.Template>
<ControlTemplate>
<Border BorderThickness="20,25,20,0"
BorderBrush="Transparent"
Background="Transparent">
<StackPanel Orientation="Horizontal"
VerticalAlignment="Top">
<Grid Margin="0 0 4 0"
Visibility="{Binding CommentsAllowedForAlbum,Converter={StaticResource BoolToVisibilityConverter}}">
<TextBlock Text="{TemplateBinding Tag}"
Visibility="{Binding SelectedPhoto.HasComments,Converter={StaticResource BoolToVisibilityConverter}}"
Foreground="{StaticResource BlueColorBrush}"
FontSize="{StaticResource MFontSize36}" />
</Grid>
<Image Source="/Images/photo_comments_icon.png"
Stretch="Uniform"
MaxWidth="23"
Visibility="{Binding CommentsAllowedForAlbum,Converter={StaticResource BoolToVisibilityConverter}}"
Margin="0 7 0 0"
VerticalAlignment="Top" />
<Image Source="/Images/photo_comments_icon_blocked.png"
Stretch="Uniform"
MaxWidth="23"
Visibility="{Binding CommentsAllowedForAlbum,Converter={StaticResource OppositeBoolToVisibilityConverter}}"
Margin="0 7 0 0"
VerticalAlignment="Top" />
</StackPanel>
</Border>
</ControlTemplate>
</Button.Template>
</Button>