Has anyone solved this: displaying graphical resources within a button
create a resource, for instance a rectangle
<UserControl.Resources>
<Rectangle x:Key="myRectangle" Fill="Red" Height="100" Width="100"/>
</UserControl.Resources>
then set the content of the button to the resource
<Button Content="{StaticResource myRectangle}"/>
when you build inside blend 4 RC you get the error "Value does not fall within the expected range."
Visual studio does not show this error.
When you run the site the button doesn't show any content.
This technique works in WPF without problems.
Anyone got any ideas?
This can be done by directly setting the shape as the button's content. For eg:
<Button Height="120" Width="120">
<Rectangle Fill="Red" Height="100" Width="100"/>
</Button>
FrameworkElement.Resources are generally used for storing nonvisual elements, brushes, etc. For your case (I think) you'll need to store your xaml as a data template, again not sure if this works with Buttons, it is used for things like ListBoxes. See here:
resources description on msdn. The link further contains pointers to information for Data Templates etc.
Related
i need a little hand on this please,
Context : Windows 10 UWP Development, C#, Visual Studio 2017
I don't understand why I can pass INotify properties in my code, but i can not in the GEDContenuPage page view, that I want to add in the left pane of my SplitView.
<SplitView Grid.Row="1"
IsPaneOpen="{Binding IsGEDOpen}"
DisplayMode="Inline"
OpenPaneLength="{Binding GEDPaneWidth}">
<SplitView.Pane>
<Grid>
<v:GEDContenuPage Visibility="{Binding IsGEDOpen, Converter={StaticResource BoolToVisibilityConverter}}" />
</Grid>
</SplitView.Pane>
<ScrollViewer >
<Grid x:Name="mainGridData" />
</ScrollViewer>
</SplitView>
IsPaneOpen="{Binding IsGEDOpen}" will works and do its job (open or close left pane)
BoolToVisibilityConverter is in app.xaml and works well (tested somewhere else)
I have also created a DependencyPropertyin my page control :
<v:GEDContenuPage
Visibility="{Binding IsGEDOpen, Converter={StaticResource BoolToVisibilityConverter}}"
ext:GEDContenuPageExtension.ContenuId="2446"
/>
Same thing here, 2446 will works well, This will open my left pane with the right content.
But I i try to replace it with a Binding :
ext:GEDContenuPageExtension.ContenuId="{Binding GedContenuId}
It won't work.
I guess this is end of the week, and the only thing I need is a fresh beer to put things right in my mind...
For your information, the left pane will receive other page than GEDContenuPage. This is why I need a visibility property for each page.
Thanks for help,
OK this was a datacontext issue, this done the trick
<Grid Name="parentGrid">
<v:GEDContenuPage Visibility="{Binding DataContext.IsGEDOpen, Converter={StaticResource BoolToVisibilityConverter}, ElementName=parentGrid}" />
I am trying to show a url from Sketchfab and I can´t get the desired results. I need to show a page like this.
https://sketchfab.com/models/dGUrytaktlDeNudCEGKk31oTJY/embed?autospin=0.3&autostart=1&ui_infos=0
If you go there you can see that the model starts to spin automatically but if I put this Url in the source property of my WebBrowser control it shows the model but I doesn´t spin. The code that I am using is this:
<phone:PanoramaItem Header="{Binding Source={StaticResource LocalizedStrings}, Path=LocalizedResources.MainPagePanoramaItemViewTitle}" Orientation="Horizontal">
<Grid>
<phone:WebBrowser x:Name="WebBrowserViewer" Background="Black" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="450"
Source="https://sketchfab.com/models/dGUrytaktlDeNudCEGKk31oTJY/embed?autospin=0.3&autostart=1&ui_infos=0"
IsScriptEnabled="True" HorizontalContentAlignment="Stretch"/>
</Grid>
</phone:PanoramaItem>
Is posible reproduce this "autospin" and adjust de viewer to the WebBrowser control ?
Thanks a lot
I am working in windows store apps and I need help..
I am trying to adapt my app for the differents visual state (FullScreenLandscape, FullScreenPortrait, Snapped, etc) and I need to reuse the controls for each visual state..
I create a grid for each visual state for example
<Grid x:Name="PortraitView" Visibility="Collapsed">
</Grid>
<Grid x:Name="FillView" Visibility="Visible">
</Grid>
<Grid x:Name="SnapView" Visibility="Collapsed">
</Grid>
but my problem is that I can not repeat the x:name of the controls that I set in the Grid= PortraitView..
how can I resolve it?
thanks
From MSDN
The most common usage of this property is to specify a XAML element
name as an attribute in markup. This property essentially provides a
WPF framework-level convenience property to set the XAML x:Name
Directive.
Names must be unique within a namescope.
For more information, see XAML Namescopes.
I have this XAML code block:
<StackPanel Orientation="Horizontal">
<TextBlock Text="Hello " />
<TextBlock Text="World" />
</StackPanel>
I would like to define this block (for example in /Common/CustomStyles.xaml) to include it on different XAML pages. How does it work?
I do not need a DataTemplate or something similar because the text is static.
You could put it in a user control and re-use it that way. If it's just the text you are interested in then you could use a resource file - this would update the textbox on any screen as long as it had the right uid.
I've been trying to get an App bar implemented in a WinRT metro app (C# / XAML), but don't know where to begin. I've tried using the <ApplicationBar/> tag and I get a Type not found error.
There's no help online, could someone update this post with the answer so that it'll serve as a reference to other programmers as well?
There's only a JavaScript sample which isn't of much help.
This should work:
<AppBar
VerticalAlignment="Bottom">
<Button
AutomationProperties.Name="Play"
Style="{StaticResource PlayAppBarButtonStyle}"
Command="{Binding PlayCommand}" />
</AppBar>
– you would put that in the layout root grid of your page.
*EDIT
Note: According to documentation - you should put it in Page.BottomAppBar property, although at least in Windows 8 Consumer Preview - it works fine when used in any Grid, which is convenient if your UI isn't tightly coupled to a Page control.
*EDIT 2, response from MSFT:
The recommended approach is to use the Page.BottomAppBar/TopAppBar properties.
There are known hit-testing issues in the Consumer Preview if AppBars are added without using these properties
The AppBars do not use the proper animations if they are added without using these properties
If AppBars are added as children of arbitrary elements then it's easier for multiple controls to attempt to create/modify AppBars, resulting in an inconsistent user experience
*EDIT 3
The CustomAppBar in WinRT XAML Toolkit can be used anywhere, animates based on Vertical/Horizontal-Alignment, can have other content overlaid on top of it and also has a CanOpen property that allows to block it from opening.
<Page.TopAppBar>
<AppBar>
<TextBlock x:Name="TextBlock1" Text="Sample Text" Margin="0,0,0,0" Height="Auto" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</AppBar>
</Page.TopAppBar>