Pivot control header icon of un selected pivot in windows phone universal application - xaml

I have pivot control in my universal windows phone application. Defined like this
<PivotItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Margin="0 0 10 0" Width="40" Source="/Assets/Images/cher.png" />
<TextBlock x:Uid="cherTextBlock" Grid.Column="1" Style="{StaticResource PivotHeadingStyle}" />
</Grid>
</PivotItem.Header>
When I am on first pivot the text of second pivot becomes dull. But offcourse the image doesn't become dull. I have same image with dull effect and I want that dul image to be shown when other pivot is shown.
One approach is that I make it programmatically and change the source of image when it is not in focus. But I want to know is that possible to do this in xaml or some other better approach than mine?

Accomplished it like programmatically
inside initialized component added this code
//RechargeAccountPivot is name of my pivot control.
RechargeAccountPivot.SelectionChanged += RechargeAccountPivot_SelectionChanged;
And this is selectionChanged event code. where i gave names to my all image controls and changed their icons.
private void RechargeAccountPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (RechargeAccountPivot.SelectedIndex == 0)
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCard.png"));// new BitmapImage { UriSource = new Uri("//Assets/Images/BalanceTopUpIcons/rechargeCard.png") };
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
}
else if (RechargeAccountPivot.SelectedIndex == 1)
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCardDull.png"));
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucher.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
}
else
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCardDull.png"));
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucher.png"));
}
}

Related

PrepareContainerForItemOverride works different in Desktop than in Mobile UWP

I wanted to change the color of an item of ListView according the data value.
It would be easy doing:
<ListView.ItemContainerStyle>
<Style TargetType = "ListViewItem" >
< Setter Property="Background" Value="{Binding EventType, Converter={StaticResource EventTypeToBackColorConverter}}" />
</ListView.ItemContainerStyle>
But the thing is that UWP does not support binding in Setter Properties.
My second attempt was overriding PrepareContainerForItemOverride of the ListView:
public class EventListView : ListView
{
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
var listViewItem = element as ListViewItem;
var ev = item as EventType;
if(ev.Warning)
listViewItem.Background = new SolidColorBrush(Color.Red);
}
}
The above code works fine running in a PC with Windows 10 and UWP. It colors in red some items according the underlying data. When I run the same app in Windows Mobile, at beginning it works fine, but when I scroll up and then I scroll down, returning to the original view that was ok at beginning, now other items are also in red color.
What I am missing?
I am not sure the reason, but the following code works for me:
public class EventListView : ListView
{
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
var listViewItem = element as ListViewItem;
var ev = item as EventType;
if(ev.Warning)
listViewItem.Background = new SolidColorBrush(Color.Red);
else
listViewItem.Background = null;
}
}
I have added listViewItem.Background = null
This is because when there are a large number of Items, by default ListView has implement the function of data virtualization. It's not a good idea to disable this function since it can achieve a better performance.
But for your scenario, there is a much easier method to solve your problem. Since you're trying to modify the style of ListViewItem in the code behind, and we can't modify the existed one, we can set a new style of ListViewItem to ListView for example like this:
private void Button_Click(object sender, RoutedEventArgs e)
{
var dynamicStyle = new Style();
dynamicStyle.TargetType = typeof(ListViewItem);
dynamicStyle.Setters.Add(new Setter(BackgroundProperty, Colors.Red));
listView.ItemContainerStyle = dynamicStyle;
}
Only one problem is, if you are setting the Background property to all the ListViewItem, it makes no difference than binding data to the Background property of ListView or setting the Background to ListView like this:
listView.Background = new SolidColorBrush(Colors.Red);
So I just assume that you want to modify the root control in the DataTemplate for example like the Grid in the following xaml:
<ListView x:Name="listView" ItemsSource="{x:Bind collection}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem" x:Name="myListItemStyle">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock Text="{Binding Testtext}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Then in this scenario, you can use data binding probably like this:
<DataTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{Binding EventType, Converter={StaticResource EventTypeToBackColorConverter}}">
<TextBlock Text="{Binding Testtext}" />
</Grid>
</DataTemplate>
Any way, if you insist to change some property of all ListViewItem in the ListView, you can use the first method I provided.

How to add autocomplete functionality for Listpicker in windows phone 8?

Hi I'm developing wp8 application .
I'm using List picker for bind city names.Below it's my code for list Picker
XAML
<toolkit:ListPicker x:Name="Lpcity" Foreground="White" BorderThickness="0" VerticalAlignment="Top" Margin="400,10,0,0" Height="80" Width="50" Visibility="Visible" SelectionChanged="Lpcity_SelectionChanged">
<toolkit:ListPicker.Background>
<ImageBrush ImageSource="/Assets/Images/search.png"/>
</toolkit:ListPicker.Background>
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding cityname}" Visibility="Collapsed" Foreground="Red"/>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock FontSize="30">
<Run Text="{Binding cityname}"/>
</TextBlock>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
C#
public void Citybind()
{
string city_nameurl = "http://xxxx.yyyyy";
WebClient city_namewc = new WebClient();
city_namewc.DownloadStringAsync(new Uri(city_nameurl), UriKind.Relative);
city_namewc.DownloadStringCompleted += city_namewc_DownloadStringCompleted;
}
void city_namewc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var city_name = e.Result;
city_namedata add = new city_namedata();
add.id = "-1";
add.cityname = "Select any one city";
add.id = "0";
add.cityname = "Remove city based search";
var city_nameval = JsonConvert.DeserializeObject<List<city_namedata>>(city_name);
city_nameval.Insert(0, add);
Lpcity.ItemsSource = city_nameval;
}
OutPut:
Now nearly 200 and more city name is bind in List picker. If user wan to select city name start with z. now he need to scroll to the bottom of the screen.
So i need to add the auto complete functionality . If user type z all z related name should show to user.
I searched in web and find out autocomplete box functionality.I try with following code for autocomplete box
XAML
<toolkit:AutoCompleteBox HorizontalAlignment="Left"
Width="450"
Grid.Row="0"
Name="autoCompleteBox1"
VerticalAlignment="Top"
InputScope="Digits"
ItemsSource="{StaticResource AutoCompletions}"
/>
Now i need to know it's possible to add both list picker and autocomplete box?
Other wise any other option available for my requirement?
Thank you

Picking Page for returning a result back to a caller

I would like to create something like CameraCaptureUI.CaptureFileAsync which will return the result to caller (location that user picked through bing maps in my case)
(the same question was asked here but I still need full screen UI or more complete code example)
Assuming the next use case:
CallerPage1 Navigate-> CallerPage2 (through Frame.Navigate(typeof(CallerPage2)) )
CallerPage2 Navigate-> LocationPickingPage (again through Frame.Navigate(typeof(LocationPickingPage )) <- here should be something else but not Frame.Navigate)
User picks a Location and presses done -> location object returned to CallerPage2
(through Frame.Navigate(typeof(CallerPage2)) )
And now if user presses back on CallerPage2 he/she will be navigated back to LocationPickingPage which is expected in navigation model described above but I wont to navigate him/her to CallerPage1
So this is how CameraCaptureUI.CaptureFileAsync behaves.
Maybe someone can help to look "behind the scenes" of CaptureFileAsync or familiar method and provide some example of how it can be implemented so that location picking can be performed like this:
Location location = await new LocationPickCaptureUI.CaptureLocationAsync();
Any help would be appreciated!
Edit
So, maybe someone can shad some light on how pages can share their data without affecting navigation history. I'm just looking for something like android's startActivityForResult.
I spend several days on this problem (msdn docs, researching different examples, forums and different sites including this one) and didn't find any approach so I think it is time to ask own question.
Sharing data between pages in manner I am looking for should be something obvious. Maybe I was looking in a wrong way but the problem is still persist's.
And please, if someone votes down my question share your mind and your source of knowledge as I still need help on this problem.
Thanks in advance
So, finally I've got an appropriate solution and maybe it can be helpful to anybody else.
The idea is to use Popup object and fit all the screen (however the details seemed like some kind of magic :) )
One thing: I used UserControl (in Visual Studio right click on project -> Add -> new item.. -> UserControl) template as in this scenario it is easy to manage popups's content
Here is the full source for C#:
CustomCaptureUI.xaml:
<UserControl
x:Class="Family.CustomCaptureUI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Family"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
x:Name="Root">
<Grid>
<Border BorderBrush="Gray" BorderThickness="1">
<Grid x:Name="Panel" Background="Gray">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="New text" Foreground="LightGray" FontSize="18"/>
<TextBox x:Name="ToDoText" Width="Auto" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Center"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="SubmitButton" Background="Gray" Content="Submit" HorizontalAlignment="Center"/>
<Button x:Name="CancelButton" Background="Gray" Content="Cancel" HorizontalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Grid>
</Border>
</Grid>
</UserControl>
CustomCaptureUI.xaml.cs:
public sealed partial class CustomCaptureUI : UserControl
{
public enum ResultStatuses
{
Canceled,
Ok,
None
}
public CustomCaptureUI()
{
_resultStatus = ResultStatuses.None;
// force content's size to preferable value
Root.Width = Window.Current.Bounds.Width;
Root.Height = Window.Current.Bounds.Width * 0.3;
// Init popup's Content
_popup.Child = this;
// Init popups's position
_popup.SetValue(Canvas.LeftProperty, (Window.Current.Bounds.Width - Root.Width) * 0.5);
_popup.SetValue(Canvas.TopProperty, (Window.Current.Bounds.Height - Root.Height) * 0.5);
}
public async Task<string> ShowDialog()
{
string result = string.Empty;
if (_semaphore != null) { DismissAddToDoPopup(); }
// Init a Task for block the ShowDialog-method until user presses Cancel or Submit
_semaphore = new Task(() => { });
CancelButton.Click += (sender, e) =>
{
_resultStatus = ResultStatuses.Canceled;
DismissAddToDoPopup();
};
SubmitButton.Click += (sender, e) =>
{
result = ToDoText.Text;
_resultStatus = ResultStatuses.Ok;
DismissAddToDoPopup();
};
ShowAddToDoPopup();
// actual blocking of ShowDialog
await _semaphore;
return result;
}
public void DismissDialog()
{
_resultStatus = ResultStatuses.Canceled;
DismissAddToDoPopup();
}
private void ShowAddToDoPopup()
{
ToDoText.Text = string.Empty;
_popup.IsOpen = true;
}
private void DismissAddToDoPopup()
{
if (_semaphore != null)
{
// starts the task and allows awaited ShowDialog-method to be released
// after _semaphore is finishing
_semaphore.Start();
_semaphore = null;
}
_popup.IsOpen = false;
}
public ResultStatuses ResultStatus
{
get { return _resultStatus; }
}
private Popup _popup = new Popup();
private Task _semaphore;
private ResultStatuses _resultStatus;
}
And then it can be used like this:
var dialog = new CustomCaptureUI();
string result = await dialog.ShowDialog();
if (dialog.ResultStatus == AddToDoDialog.ResultStatuses.Ok)
{
// Useful stuff
if (!string.IsNullOrWhiteSpace(result))
{
...
}
}
Hope it can save someone's time a little

custom live tile update issue

I'm working on a weather application for windows phone. One of the features that I want to take advantage of is live tiles. I have a background agent that runs when the user pins a city to the start page.
After it's been pinned, it makes a calls out to the internet to get some weather data. All of this works just fine.
Now for the problem.
Depending on the weather data that's returned, I want to update the tiles that are pinned to the start screen.
I have a number of different .xaml files (rain, snow, sun, etc) that represent each tile.
My first thought was that I would:
expose 2 properties on each tile (CityState and Temp)
set those 2 properties after the tile is created.
save the tile off into IsolatedStorage as an image that I can then use to update the tile on the start screen.
Here is the code that I have to do that:
var ctl = new Snow();
//just some dummy data to test
ctl.CityState = "Test, NY";
ctl.Temp = 25;
ctl.Measure(new Size(173, 173));
ctl.Arrange(new Rect(0, 0, 173, 173));
var bmp = new WriteableBitmap(173, 173);
bmp.Render(ctl, null);
bmp.Invalidate();
var iss =IsolatedStorageFile.GetUserStoreForApplication();
var filename = "/Shared/ShellContent/tileTest.jpg";
using (var stm = iss.CreateFile(filename))
{
bmp.SaveJpeg(stm, 173, 173, 0, 80);
}
tile.BackgroundImage = new Uri("isostore:" + filename, UriKind.Absolute);
var tileToUpdate = ShellTile.ActiveTiles.FirstOrDefault(r => r.NavigationUri == uri);
tileToUpdate.Update(tile);
So, when this runs, it creates a new tile from the XAML file and updates the start screen but the Temp and CityState properties
are not reflected on the new Tile. In the xaml I have 2 textblocks that are bound to the properties in the codebehind. I've also
implemented INotifyPropertyChanged.
Here is the XAML
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Name="Window"
x:Class="ezweather.services.tiles.Snow"
d:DesignWidth="480" d:DesignHeight="800" Width="173" Height="173" >
<Canvas x:Name="Layer_1" Width="173" Height="173" Canvas.Left="0" Canvas.Top="0" >
<Rectangle x:Name="Rectangle" Width="173" Height="173" Canvas.Left="0" Canvas.Top="-1.52588e-005" Stretch="Fill" Fill="#FF3F6A8D"/>
<TextBlock x:Name="cityState" TextAlignment="Left" FontFamily="Segoe UI Semibold" FontWeight="Bold" FontSize="15" Width="Auto" Height="Auto" Canvas.Left="0" Canvas.Top="0">
<TextBlock.RenderTransform>
<TransformGroup>
<MatrixTransform Matrix="1.33333,0,0,1.33333,11,139.5"/>
</TransformGroup>
</TextBlock.RenderTransform>
<Run Text="{Binding ElementName=Window, Path=CityState}" Foreground="#FFFFFFFF"/>
</TextBlock>
<TextBlock x:Name="temp" TextAlignment="Right" FontFamily="Segoe UI Light" FontSize="44" Width="Auto" Height="Auto" Canvas.Left="0" Canvas.Top="0">
<TextBlock.RenderTransform>
<TransformGroup>
<MatrixTransform Matrix="1.33333,0,0,1.33333,87.57,42.9333"/>
</TransformGroup>
</TextBlock.RenderTransform>
<Run Text="{Binding ElementName=Window, Path=Temp}" Foreground="#FFFFFFFF"/>
</TextBlock>
</Canvas>
</UserControl>
and here is the codebehind
public partial class Snow : UserControl, INotifyPropertyChanged
{
public Snow()
{
// Required to initialize variables
InitializeComponent();
}
private string _cityState;
private int _temp;
public string CityState
{
get { return _cityState; }
set
{
_cityState = value;
RaisePropertyChanged("CityState");
}
}
public int Temp
{
get { return _temp; }
set
{
_temp = value;
RaisePropertyChanged("Temp");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string property)
{
if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
When this code runs, it instantiates the correct xaml file and saves it to disk.
It then updates the tile on the start screen but the CityState and Temp data does not show up.
I don't know why the CityState and Temp data isn't being written out with the image.
What am I missing?
The primary issue I see here, is you're attempting to render the image, before the control is actually loaded.
Try handle the rendering in the Control.Loaded event.

How to show part of text in datagrid row details?

I have table in my database which has fields of ID,NAME,CONTEXT. I am showing search result in datagrid. Now I tried to do this
<WpfToolkit:DataGrid.RowDetailsTemplate>
<DataTemplate>
**<StackPanel Orientation="Horizontal" Margin="5">
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Foreground="CadetBlue" FontSize="13"
Width="Auto" TextWrapping="Wrap"
Text="{Binding Path=Context}"/>
</StackPanel>**
</StackPanel>
</DataTemplate>
</WpfToolkit:DataGrid.RowDetailsTemplate>
It is giving whole text which is not what I want. If you give me some directions how to do this, may be some code. It will be appreciated. I want to show only that part of text which is selected by this line of code.
private void Find_Click(object sender, RoutedEventArgs e)
{
DataSet ds = new DataSet();
cmdSel = new SqlCommand();
cmdSel.Connection = MainWindow.conn;
cmdSel.CommandText = "select id,Name,Context from document where Contains([Context],'FormsOf (INFLECTIONAL, \"" + TextBoxSearch.Text + "\")')";
da = new SqlDataAdapter(cmdSel);
da.Fill(ds, "MainSearchBinding");
resWin.DataGrid1.DataContext = ds;
}
For example you are searching for "audio" and it is showing 10 words before + "audio" + 10 word after audio. Thank in advance.
I add one more column "Intro" to my table.
<WpfToolkit:DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="5">
<StackPanel Orientation="Vertical" Margin="5" >
<TextBlock Foreground="CadetBlue" FontSize="13"
Width="Auto" TextWrapping="Wrap"
Text="{Binding Path=Intro}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</WpfToolkit:DataGrid.RowDetailsTemplate>
And wrote this code for mouse click.
private void OnMouseClick(object sender, MouseButtonEventArgs e)
{
IList rows = DataGrid1.SelectedItems;
DataRowView row = (DataRowView)DataGrid1.SelectedItems[0];
int a = (int)row["ID"];
string t = (string)row["Context"]; //getting all text from Context
string srch1 = UCSearch.srch; // search box text
if (t.IndexOf(srch1) != -1)
{
string retString = t.Substring(t.IndexOf(srch1), 100); //cutting from occured text and more 100 symbols
row["Intro"] = retString; // setting to Intro Column
}
}
I hope some one may need it. Thank you.