I created a simple Windows 8 app with a single page and a flipview. My goal is to slide through a set of images. Microsoft suggests to use a context indicator for image galleries with larger amount of images (I have 25 photos).
So for starters: I hope that flipview is the correct tool to my needs?
And how can I add a context indicator to an existing flipview? So far I added the flipview to the xaml file:
<FlipView x:Name="flipView" Grid.Row="1" VerticalAlignment="Top" Background="Black"/>
Also I added some images in C#:
ImageBrush brush1 = new ImageBrush();
brush1.ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/gallery/IMG_0001.jpg"));
FlipViewItem flipvw1 = new FlipViewItem();
flipvw1.Background = brush1;
flipView.Items.Add(flipvw1);
etc...
Check this blog post that describes how to implement one:
http://blogs.u2u.be/diederik/post/2012/08/24/A-CXAML-FlipView-Context-Indicator-for-Windows-8.aspx
Also Callisto includes the implementation that you can just grab from NuGet:
https://github.com/timheuer/callisto/blob/master/src/Callisto/Controls/FlipViewIndicator/FlipViewIndicator.cs
Related
I'm using XAML Islands to make my app and I want to use Windows 10 styling in my WPF app like here. For example <TextBlock Text="Header" Style="{StaticResource HeaderTextBlockStyle}"/> would result in:
But this doesn't work in WPF (It does work in UWP without any modifications), my understanding is that XAML Islands should make it possible. When I try to simply add the code above to my xaml file I get the exception
Cannot find resource named 'HeaderTextBlockStyle'. Resource names are case sensitive.
I get the same exception if I add Style="{StaticResource HeaderTextBlockStyle}" to a <xamlhost:WindowsXamlHost> element.
So I tried to add the controls with code so I added this WindowsXamlHost control as a stackpanel:
<xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.StackPanel" ChildChanged="WindowsXamlHost_ChildChanged"/>
And added this method (an event handler that is ran when the control is made. Learned it from this) that handles adding additional controls (a TextBlock) to the StackPanel:
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
{
// Get the host control
WindowsXamlHost host = (WindowsXamlHost)sender;
// Get the StackPanel in the host
Windows.UI.Xaml.Controls.StackPanel sp = (Windows.UI.Xaml.Controls.StackPanel)host.Child;
// Make a TextBlock to add to the StackPanel
Windows.UI.Xaml.Controls.TextBlock textBlock = new Windows.UI.Xaml.Controls.TextBlock();
// Set the text of the TextBlock
textBlock.Text = "LockCursorInMonitor";
// Get the style resources, cast them to the appropriate type for XAML Islands and add them to the TextBlock
textBlock.Style = (Windows.UI.Xaml.Style)Application.Current.Resources["HeaderTextBlockStyle"];
// Another way to get resources but this doesn't work too.
//textBlock.Style = (Windows.UI.Xaml.Style)this.FindResource("HeaderTextBlockStyle");
// Add the TextBlock to the stackpanel
sp.Children.Add(textBlock);
}
The Application.Current.Resources["HeaderTextBlockStyle"] way does nothing and doesn't throw an exception.
The this.FindResource("HeaderTextBlockStyle") way throws the next exception:
System.Windows.ResourceReferenceKeyNotFoundException: ''HeaderTextBlockStyle' resource not found.'
So how can I get these style resources in my WPF app?
One way to achieve this is to use the package ModernWPF but then you lose all the benefits of XAML Islands (if there are any. Everything I needed from XAML Islands is in ModernWPF and is easier to implement).
After installing and setting ModernWPF up you can simply use the <TextBlock Text="Header" Style="{StaticResource HeaderTextBlockStyle}"/> way and it just works.
How to set an specific image as a Fluent Design AcrylicBackgroundSource to use in PIP mode (CompactOverlay) like Groove Music PIP feature
The picture-in-picture in UWP applications is strictly a compressed version of the current page. You may see the difference between Groove in normal view and compression attempts, but the principle of implementing Acrylic Brush is the same.
Considering the question you asked, here is a possible way to achieve image blur:
XAML
<Page
...>
<Page.Resources>
<ImageBrush ImageSource="{Here is your image url}" x:Key="ImageBackground" Stretch="UniformToFill"/>
<AcrylicBrush x:Key="MaskBackground" BackgroundSource="Backdrop" TintColor="Black" TintOpacity="0.3" FallbackColor="Black"/>
</Page.Resources>
<Grid Background="{StaticResource ImageBackground}" Name="ImageLayer">
<Grid Background="{StaticResource MaskBackground}" Name="MaskLayer"/>
<Grid>
<!-- Here is other controls, like play button etc. -->
</Grid>
</Grid>
</Page>
Usage
This is done using a layer approach. Set the background to a picture, then add a mask layer.
If you want to change the background image dynamically, you can remove the static reference and change it with C# code.
var backgroundBrush = new ImageBrush();
backgroundBrush.ImageSource = new BitmapImage(new Uri("Here is your image url"));
ImageLayer.Background = backgroundBrush;
Best regards.
I have a simple splitview that has a rectangle of width 4px that indicates the selected item in the spiltview.
<Rectangle HorizontalAlignment="Left" VerticalAlignment="Top"
Width="4" Height="48" Margin="1,0"
Fill="{ThemeResource SystemAccentColor}" Grid.Row="2"
Visibility="{x:Bind btnHome.IsChecked, Mode=OneWay}"/>
Right now I've multiple rectangles turned on/off depending whether the checkbox is selected or not! But instead, I want a single rectangle in my code that should transition from the place where it previously was to place where the user has clicked.
Simplest for you would be using the new NavigationView if your minimum version is set to Fall Creators Update or use the HamburgerMenu control from UWP Community Toolkit (note that it's updated to use style very similar to yours, the docs aren't just updated with current screenshots). You can download the UWP Community Toolkit Sample App from Windows Store if you want to see how it currently looks.
If you want to use your custom solution, you should create a custom style or rather edit an existing style of the control you're using as hamburger menu items. Default styles are available for example here.
I created a UI using XAML, in windows phone 7. I want to know if this code exists as C# code in some file and if it is so, where is the designer code, generated by the xaml?
If you want to create StackPanel programmatically, you can do it by "mimicking" the XAML version.
For example, the following XAML:
<StackPanel Foreground="White"
Margin="12,0,0,0">
</StackPanel>
can be created with the following C# code:
var stackPanel = new StackPanel();
stackPanel.Foreground = new SolidColorBrush("White");
stackPanel.Margin = new Thickness(12,0,0,0);
Without knowing what your StackPanel looks like, I cannot offer you any tipss.
I must wonder why you want to do that? XAML is generally far better to design than doing it in via code. Not to mention it is cleaner and is adaptable to MVVM which is the best solution for your application.
If you offer some more details, I can offer precise advice.
When you create code in XAML this code in C# doesn't exist in any file in your project.
The XAML code is changed to object in compilation process.
Here You have great article about this process:
Article
You can create GUI in code behind using objects like this:
var stackPanel = new StackPanel();
I have a WPF C# project that I am working on and I have multiple (25) Image controls arranged in table (5 columns, 5 rows). Each Image control is called "Image[row][column]" (eg:Image15).
Assigning a different source to the control works fine with ony one problem. No matter which control I use (Image11, Image12, Image 55) it affects Image11. No matter which one I try to change I'll end up changing the first one (Image11). This is the source change code:
BitmapImage src3 = new BitmapImage();
src3.BeginInit();
src3.UriSource = new Uri(#"D:\Electricity\CONSUMER_ON.jpg");
src3.EndInit();
Image15.Source = src3;
This does change the image but acts as if I had written "Image11.Source = src3;". Here's the XAML code just in case it might have anything to do with it.
<Image Height="150" HorizontalAlignment="Left" Margin="11,10,0,0" Name="Image11" Stretch="Fill" VerticalAlignment="Top" Width="150" />
... 23 more lines removed ...
<Image Height="150" HorizontalAlignment="Left" Margin="635,634,0,0" Name="Image55" Stretch="Fill" VerticalAlignment="Top" Width="150" />
if you need any other info, please ask. The images are 200x200 and in JPEG format and are displayed correctly (in the wrong place). The Images for the controls are determined and loaded at run-time.
Are you remembering to create a new BitmapImage for each image control, or are you recycling the same object but changing its contents when you move between images? If you set the source of two Image controls to the same ImageSource and then alter that image, both controls will reflect the changes.