print from resources (resw) directly in view on uwp | WPF - c#

Hi guys i'm building a Universal Windows App for windows 10 IOT.
So, I'didn't found a method to get a label value from resources file, directly from WPF.
There is a method like this:
<Button Content="{x:StaticResources local:mylabel" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Name="btnUpdate" Margin="0,200,0,0" MinWidth="300" Command="{Binding add}" />
on the "normal" WPF it's easy, but on universal windows app I didn't
found a solution.
The resources file within on Resources folder in my solution, while the page it's in view folder.
Thanks

In UWP you can use x:Uid directive to associate a control with a string resource identifier:
<Button x:Uid="mylabel" Name="btnUpdate" .... Command="{Binding add}" />
Please refer to MSDN for more information: https://learn.microsoft.com/en-us/windows/uwp/app-resources/localize-strings-ui-manifest

Related

where to put images for xamarin forms application

I am developing an application for Android, iOS and Visual Studio using Xamarin
I added the following lines in xaml to use images:
<Image Source="header.png" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
<Button x:Name="Object_Detection" Image="header.png" />
The first is for displaying an image in the header and the second is for displaying a button icon. They link for the same image "header.png"
I put the image under:
- Mobile.Droid\Resources\drawable
- Mobile.iOS\Resources
-Mobile.Windows\Assets
But the image is not shown at all in the Windows 8.1 app.
the image size is 690*79.
how to resolve the problem?
You have to place images in the root Project directory for Windows Phone 8, Windows Phone 8.1 and UWP applications.
This guide will help you
http://developer.xamarin.com/guides/xamarin-forms/working-with/images
Try something like this :
<ContentPage.Resources>
<ResourceDictionary>
<OnPlatform x:Key="ImageHeaders"
x:TypeArguments="ImageSource"
iOS="header.png"
Android="header.png"
WinPhone="Assets/header.png" />
</ResourceDictionary>
</ContentPage.Resources>
<Image Source="{StaticResource ImageHeaders}" />
OR
<Image.Source>
<OnPlatform x:TypeArguments="ImageSource">
<OnPlatform.iOS><FileImageSource File="header.png"/></OnPlatform.iOS>
<OnPlatform.Android><FileImageSource File="header.png"/></OnPlatform.Android>
<OnPlatform.WinPhone><FileImageSource File="Assets/header.png"/></OnPlatform.WinPhone>
</OnPlatform>
</Image.Source>
Not tested, but it seems to work well.
Thanks for all your posts,
the solution was to add the image resource to the windows sub-project directly under the root.
The addition should be made using visual studio so that the image will be taken in consideration by the compiler.

Class Library not including images

I have a class library that is essentially a collection of forms to be run. Consider it a module/plugin in a larger program, that can be developed independently, all the larger program cares about is the DLL (and interface).
Running the main form of the class library is fine and works well. My issue is with pictures. I've set up an Images folder in the class library, added an image, set it's Build Action to Embedded Resource and then rebuilt the project, but the images won't appear in the main program.
XAML:
<Button x:Name="btnAdd" Command="{Binding Add}">
<StackPanel Orientation="Horizontal">
<Image x:Name="imgAdd" Source="Resources/Add.png"/>
<Label>New</Label>
</StackPanel>
</Button>
The interesting part though, is that if I create a BitmapSource in code-behind and assign it to imgAdd in the constructor of the form, it works as expected. Does anyone have any ideas as to why this might be the case?
Use Pack URIs for your images.
<Button x:Name="btnAdd" Command="{Binding Add}">
<StackPanel Orientation="Horizontal">
<Image x:Name="imgAdd" Source="pack://application:,,,/ReferencedAssembly;component/Resources/Add.png"/>
<Label>New</Label>
</StackPanel>
</Button>
It turns out that the correct Build Action is actually Resource rather than Embedded Resource. Thinking about it now, Embedded Resource does seem more like a reference to a Resource in another DLL.
I inadvertently found the answer in this post while trying to improve my code.

Add popup menu to AppBarButton

I want to add a contextual menu to a button from the appBar(bottom appBar). My min SDK is Windows 8.0. I would like something like this popup from MSDN:
Unfortunately I cannot use MenuFlyout since it is available only from Windows 8.1+, so I want to achieve this menu in another way. If you know how it can be done, please tell me.
Below is my bottom bar:
<common:LayoutAwarePage.BottomAppBar>
<AppBar x:Name="bottomAppBar" Padding="10,0,10,0" DataContext="{Binding}">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Button Style="{StaticResource EditAppBarButtonStyle}" Click="EditQuote_Click"/>
<Button Style="{StaticResource RemoveAppBarButtonStyle}" Click="RemoveQuote_Click"/>
<Button Style="{StaticResource AddAppBarButtonStyle}" Click="AddQuote_Click"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Style="{StaticResource HelpAppBarButtonStyle}"/>
</StackPanel>
</Grid>
</AppBar>
You should take a look at the Flyout Settings sample at:
http://code.msdn.microsoft.com/windowsapps/Settings-Flyout-eceaafea
Or if you are targeting Windows 8.1, flyouts have become much easier, check the MenuFlyout element:
http://msdn.microsoft.com/en-us/library/windows/apps/bg182878.aspx#menuflyout
I would look at the Callisto library on Nuget. It's built by Tim Heuer who's one of the guys working on the xaml team at Microsoft and fills in some of the gaps in the 8.0 control set. It includes a Menu Flyout control that looks not that coincidentally like the controls added in 8.1.
The samples app in the project includes an example of what you're looking for (a Menu Flyout from an App Bar).
Edit: If you're targeting Windows 8.1 with your project then the Menu Flyout control is now built into the platform.

how to create an auto complete search textbox in windows 8

I found that Windows 8 textbox has a property "IsPredictionEnabled". I understand it is used for enable autocomplete features. But setting this property has no effect even with soft keyboards.
And If i want this search textbox to search bing and retrieve some images corresponding to the search query, how can this be done?
Thank you,
Better use a cutsom control like this:
AutoCompleteBoxWinRT
To get search results from bing You need to use bind api:
Bing API
To use AutCompleteBoxWinRT:
Import namespace:
xmlns:ab="using:AutoCompleteBox"
Place control:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<ab:AutoCompleteBox Name="ABBox" Text="{Binding Text, Mode=TwoWay}" WatermarkText="Type something" />
<Button Content="Test" VerticalAlignment="Top" Margin="0,100,0,0" Command="{Binding TestCommand}" />
</Grid>
Here You can download a sample app: LINK

silverlight toolkit listpicker wp7 missing icons

I'm having a problem with the listpicker (SelectionMode="Multiple"!!!). When i go to fullmode it doesnt show "done", "cancel" icons like if the images were not in my project.
On full screen mode i only have this xaml code
<DataTemplate x:Key="listPickerFullModeItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontSize="30" Height="40" FontFamily="Segoe WP"/>
</StackPanel>
</DataTemplate>
<toolkit:ListPicker Header="Floral" SelectionMode="Multiple" FullModeHeader="Floral" CacheMode="BitmapCache" x:Name="floralListPicker" Margin="0,0,12,0" ItemTemplate="{StaticResource listPickerItemTemplate}" FullModeItemTemplate="{StaticResource listPickerFullModeItemTemplate}"/>
Code is ok, everything works fine but the icons doesn't show, actually it shows as the default app bar missing icon image. I copied the images from toolkit sample but no go.
anyone know whats wrong?
anyway to force icons on template?
thanks.
Do you need to set the Build Action of the icons to "Content" in their properties window?
I found out the solution by exploring the sample solution of the toolkit.
If you don't use a special page for the fullmode selection, you need to include the following images to your project:
Create one subfolder named Toolkit.Content (not ToolKit/Content).
Then, include the files named as this : ApplicationBar.Cancel.png and ApplicationBar.Check.png.
Mark them to be generated as content.
That's all! Your icons should now been displayed.
Hope this helps you !

Categories