Blend does not display localized string - windows-runtime

I am writing a Windows 8 store app in xaml and c#, and am localizing strings using the approach outlined in msdn .
It shows the string correctly when the app runs, but in Expression Blend design-time it always shows an empty string.
<TextBlock x:Uid="IDST_LOAD_TITLE" x:Name="pageTitle" Text=""
Grid.Column="1" IsHitTestVisible="false"
Style="{StaticResource PageHeaderTextStyle}"/>
I've tried even getting rid of Text="" completely...
Any way to get this to work?
Thank you

I solved it this way:
create a class such as:
public class Strang
{
public string IDST_LOAD_TITLE
{ get { return Strings.IDST_LOAD_TITLE; } }
public string IDST_SAVE_TITLE
{ get { return Strings.IDST_SAVE_TITLE; } }
...
add it to your app.xaml:
<Application
x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myApp="using:MyApp"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- Look here! -->
<myApp:Strang x:Key="Strang" />
</ResourceDictionary>
</Application.Resources>
</Application>
and then in your page's xaml code, do something like so:
<TextBlock
x:Name="m_titleStatic"
Text="{Binding IDST_LOAD_TITLE}"
DataContext="{StaticResource Strang}"
/>

Related

How to refresh a StatusBar based on several ViewModels?

I develop an Universal App, that uses MVVM Light and Navegar. In this app, the main page contains a Pivot, where each PivotItem is bounded to a ViewModel.
This page looks like this:
The XAML looks like this:
<Page
...>
<Page.DataContext>
<Binding Path="MainViewModelInstance" Source="{StaticResource Locator}"/>
</Page.DataContext>
<Page.Resources>
...
</Page.Resources>
<Grid>
<!-- HOME -->
<Pivot x:Uid="homePivot"
x:Name="homePivot"
CommonNavigationTransitionInfo.IsStaggerElement="True"
TitleTemplate="{StaticResource AppPivotTitle}"
Style="{StaticResource CustomizedPivot}">
<Pivot.Background>
<ImageBrush Stretch="Fill"/>
</Pivot.Background>
<PivotItem x:Uid="homePivotitemHome"
Margin="19,14.5,19,0"
CommonNavigationTransitionInfo.IsStaggerElement="True"
Header="Home">
<PivotItem.Background>
<ImageBrush ImageSource="{Binding Infos.background_image, Converter={StaticResource InfosUIImageFondToStringConverter}}"
Stretch="UniformToFill"
Opacity="0.75"/>
</PivotItem.Background>
</PivotItem.ContentTemplate>
</PivotItem>
<!-- NEWS -->
<PivotItem x:Uid="homePivotitemNews"
Margin="19,14.5,0,0"
CommonNavigationTransitionInfo.IsStaggerElement="True" >
<PivotItem.DataContext>
<Binding Path="NewsViewModel" Source="{StaticResource Locator}"/>
</PivotItem.DataContext>
<PivotItem.ContentTemplate>
<DataTemplate>
<Grid>
<ListView ItemsSource="{Binding News}"
IsItemClickEnabled="True"
SelectionMode="Single"
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
...
</ListView>
</Grid>
</DataTemplate>
</PivotItem.ContentTemplate>
</PivotItem>
<!-- CONTACTS -->
<PivotItem x:Uid="homePivotitemContacts"
Margin="19,14.5,0,0"
CommonNavigationTransitionInfo.IsStaggerElement="True"
Header="Contacts">
<PivotItem.DataContext>
<Binding Path="ContactsViewModel" Source="{StaticResource Locator}"/>
</PivotItem.DataContext>
<PivotItem.ContentTemplate>
<DataTemplate>
<Grid>
<ListView ItemsSource="{Binding Contacts}"
IsItemClickEnabled="True"
SelectionMode="Single"
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
...
</ListView>
</Grid>
</DataTemplate>
</PivotItem.ContentTemplate>
</PivotItem>
...
</Pivot>
</Grid>
</Page>
So the page is bounded to a DataContext "MainViewModelInstance", that is used for the first PivotItem. The others PivotItems have their own DataContext: "NewsViemodel", "ContactsViewModel", ...
On each ViewModel, a constrctor calls a Load() method that updates the datas of this HomePage.
I would like to display a StatusBarProgressIndicator when one of the ViewModels is loading datas, and stopping it when all datas has been loaded.
Currently I show the StatusBarProgressIndicatorby calling a "ShowStatusBarProgress()" method in the "MainViewModel":
private async void LoadData()
{
ShowStatusbarProgress();
// Load data
...
HideStatusbarProgress();
}
private async void ShowStatusbarProgress()
{
progressbar.Text = "Please Wait...";
await progressbar.ShowAsync();
}
private async void HideStatusbarProgress()
{
await progressbar.HideAsync();
}
But I don't see how to do for taking into account all the "Load()" methods of the ViewModels. I heard about Messenger services, but I don't see how it can work in my case.

Populate ScrollView at runtime in WIndows Phone 8

I have an app for windows phone 8 that displays data loaded from my website.
At the moment, I have setup 4 'holders' for the data, that contain a few TextBlocks and Images. When the app is loaded, these 4 holders display the data for the first 4 'records'. To display the next 4 'records', the user has to click a button, 'Next'.
I want to change this so that all 'records' are displayed in a ScrollView so the user simply has to scroll down to view records rather than click the 'Next' button.
I have also written the app for Android using Eclipse and Java. To do the above, I created a layout of the 'holder' in xml and then this is used as a template for the data. I only have to define the layout once and it is repeated at runtime, populated with the data from each record.
How do I achieve the same in Windows Phone, using vb.net and xaml?
I have googled and possibly DataTemplate is what I need however I'm not sure and have no idea how to implement it.
If you could point me in the right direction I'm sure I can figure it out!
Thanks in advance.
EDIT:
Ok, I've tried the following but the ListBox is empty:
Basically I have a List populated at runtime from my website (I know this bit works):
Public WebData As New System.Collections.Generic.List(Of WebInfo)
WebInfo Class:
Public Class WebInfo
Public ID As Integer
Public H1 As String
Public A1 As String
Public C1 As String
Public C2 As String
Public K1 As Date
End Class
xaml:
<ListBox x:Name="MainList" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Grid.Row="3" Grid.RowSpan="6" Grid.Column="0" Grid.ColumnSpan="3">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="H1" Text="{Binding H1}" FontSize="15" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Right" TextAlignment="Right" FontWeight="Bold" Foreground="Black"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I try to set the ItemsSource using:
MainList.ItemsSource = WebData
The ListBox does not populate.
Any Thoughts?
I think LongListSelector works for you, but you should edit DataTemplate for your needs.
<phone:LongListSelector ItemsSource="{Binding ArticleList}">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Title:" />
<TextBlock Text="{Binding Title}" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
The problem was, I was using variables in my class rather than properties:
Public Class WebInfo
Public Property ID As Integer
Public Property H1 As String
Public Property A1 As String
Public Property C1 As String
Public Property C2 As String
Public Property K1 As Date
End Class
Thanks for your help.

Want to launch the view that exists in the views sub folder using mvvmcross

In PCL Core project I have sub folder in ViewModels folder as TestViewMdoels and in that I have a FirstViewModel.cs. And in Phone UI project I have sub folder in Views folder as TestViews and in that i have FirstView.xaml. Up on launching my windows app i need to show FirstView as start up page.
Please guide me to build the sub folders in views and viewmodels folder using mvvmcross.
Thanks
Hari
UPDATE 1
public class FirstViewModel : MvxViewModel
{
private string _hello = "MvvmCross";
public string Hello {
get { return _hello; }
set { _hello = value; RaisePropertyChanged(() => Hello); }
}
}
Code in FirstView.xaml
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock HorizontalAlignment="Left" Margin="40,79,0,0"
TextWrapping="Wrap" Text="{Binding Hello}"
VerticalAlignment="Top" Width="291"/>
</Grid>
</Grid>
In your Core project, find the file App.cs, there is the overrided method Initialize(), so in this method in the end add RegisterAppStart<ViewModels.TestViewModel.FirstViewModel>();
*if there is RegisterAppStart already exist in that method, remove it and add your one
also please look through Stuart "N+1 days of MvvmCross" lessons, here is the link to the first one - N=0 : A first MvvmCross Application
In his blog you can also find the other great lessons (more then 40) about MvvmCross

Displaying key/value pairs

I have a bunch of key/value pair text data that I need to display.
I currently use LongListSelector with an ItemTemplate which uses a horizontal StackPanel with two TextBlock s inside:
<StackPanel Orientation="Horizontal">
<TextBlock Text="Title: " />
<TextBlock Text="{Binding Path=Title}" TextWrapping="Wrap" />
</StackPanel>
This gives a nice "label: value" look.
However, I find this verbose.
Is there a nicer way to achieve the same thing?
I've tried putting everything in a single TextBlock like so:
<TextBlock Text="Title: {Binding Path=Title}" TextWrapping="Wrap" />
but it doesn't want to work!
Inside a single TextBlock, this is not possible. However, you could use a ValueConverter:
public class NameValueConverter : IValueConverter
{
public object Convert(Object value,
Type targetType,
Object parameter,
CultureInfo culture)
{
return "Title: " + (string)value;
}
}
You should add this to your app.xaml as a global resource (named NameValueConverter). Then you can do this in XAML:
<TextBlock Text="{Binding Path=Title, Converter={StaticResource NameValueConverter}}" TextWrapping="Wrap" />
When databinding kicks in, it will pass the Title to the valueconverter and bind the result to the textbox.

How to display flatlist using LongListSelector phone control of WP8

In toolkit LongListSelector, there used to be a property IsFlatList which needed to be set to true to display flat list without any grouping. But in the LongListSelector provided in phone control, this property is missing. Here is what I am doing
<phone:LongListSelector Name="myList" IsGroupingEnabled="False" LayoutMode="List" ItemsSource="{Binding Source ={StaticResource SortedList} }" CacheMode="BitmapCache" >
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<components:MyControl CacheMode="BitmapCache" MyItem="{Binding}"/>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
If I change the control to ListBox and remove LongListSelector specific property then it display my list.
Can someone please tell me what I am missing?
I am following this(Remarks) documentation of LongListSelector
In the Windows Phone 8 Version of the LongListSelector setting LayoutMode to List and IsGroupingEnabled to false should display your databound data as a flat list like in the WP7 Toolkit version of the control.
For example,
Given an Entity class
public class Entity
{
public string Name
{
get;
set;
}
public string Info
{
get;
set;
}
public int ID
{
get;
set;
}
}
All I need to do is create an ObservableCollection of Entity on my page and bind it to the itemsource of my LongListSelector (named list).
ObservableCollection<Entity> data = new ObservableCollection<Entity>();
list.ItemsSourdce = data;
Then I create the entities and add them to the collection.
Here is the XAML for my LongListSelector:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:LongListSelector Name="list" HorizontalAlignment="Left" Height="609" VerticalAlignment="Top" Width="456" LayoutMode="List" IsGroupingEnabled="False" >
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Top">
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
<TextBlock Text="{Binding Info}" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
LayoutMode ="List" that's all you need.