I'm sure this is simple, but I'm not finding the solution. how do I bind to two arrays within a data source with one ListBox?
Here is a sample of the data:
<XmlDataProvider x:Key="ConfigurationData" XPath="Configuration/Component">
<x:XData>
<Configuration xmlns="">
<Component ID="2252371">
<ComponentAttribute ID="301080453">
<Name>ColorHexCodes</Name>
<Value />
<Values>
<Value>#FFFFFA</Value>
<Value>#FFFFFA</Value>
<Value>#FFFFFA</Value>
<Value>#FFFFFA</Value>
<Value>#FFFFFA</Value>
<Value>#FFFFFA</Value>
<Value>#A80000</Value>
<Value>#A80000</Value>
<Value>#A80000</Value>
<Value>#A80000</Value>
<Value>#A80000</Value>
<Value>#A80000</Value>
<Value>#D1D3D4</Value>
<Value>#D1D3D4</Value>
<Value>#D1D3D4</Value>
<Value>#D1D3D4</Value>
<Value>#D1D3D4</Value>
<Value>#D1D3D4</Value>
</Values>
</ComponentAttribute>
<ComponentAttribute ID="301080500">
<Name>ColorDescription</Name>
<Value />
<Values>
<Value>0010 - White</Value>
<Value>0010 - White</Value>
<Value>0010 - White</Value>
<Value>0010 - White</Value>
<Value>0010 - White</Value>
<Value>0010 - White</Value>
<Value>1902 - Red</Value>
<Value>1902 - Red</Value>
<Value>1902 - Red</Value>
<Value>1902 - Red</Value>
<Value>1902 - Red</Value>
<Value>1902 - Red</Value>
<Value>3971 - Silver</Value>
<Value>3971 - Silver</Value>
<Value>3971 - Silver</Value>
<Value>3971 - Silver</Value>
<Value>3971 - Silver</Value>
<Value>3971 - Silver</Value>
</Values>
</ComponentAttribute>
</Component>
</Configuration>
</x:XData>
</XmlDataProvider>
What I need to show is the list that shows the ColorDescription and ColorHexCodes side by side. These two collections will always line up.
I came up with this:
<ListBox Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto" Width="Auto" Grid.ColumnSpan="2">
<ListBox.ItemsSource>
<Binding Source="{StaticResource ConfigurationData}" XPath="//ComponentAttribute[Name='ThreadDescription']/Values/*" />
</ListBox.ItemsSource>
<ListBox.ItemTemplate>
<DataTemplate x:Key="Swatch">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Height="20" FontSize="14" Foreground="CadetBlue">
<TextBlock.Text>
<Binding XPath="//ComponentAttribute[Name='ColorDescription']/Values/Value" />
</TextBlock.Text>
</TextBlock>
<TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Height="20" Margin="20,0,0,0" FontSize="14" Foreground="CadetBlue">
<TextBlock.DataContext></TextBlock.DataContext>
<TextBlock.Text>
<Binding XPath="//ComponentAttribute[Name='ColorHexCodes']/Values/Value" />
</TextBlock.Text>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
It renders the correct number of ListBoxItems, but is only displaying the first value in each item. Where am I going wrong? I know this has to be something really easy I'm just missing.
Look into the use of a Composite Collection storage which can hold both of your lists, but be used to be bound to by one listbox and handle each item type specifically.
The link to MSDN gives an example of showing two different data items in one display.
Related
I´m designing a login screen, this is my xaml
I can't to increase the grid size background red, because i put alot of "entry" but these disappear, if you know any property please give me your advices
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
<ContentPage.Content>
<yummy:PancakeView
BackgroundGradientStartPoint="0,1"
BackgroundGradientEndPoint="1,0"
Margin="0,0,0,10"
HorizontalOptions="FillAndExpand"
CornerRadius="0,0,400,0">
<yummy:PancakeView.BackgroundGradientStops>
<yummy:GradientStopCollection>
<yummy:GradientStop Color="#155cab" Offset="0" />
<yummy:GradientStop Color="#155cab" Offset="0.5" />
</yummy:GradientStopCollection>
</yummy:PancakeView.BackgroundGradientStops>
<StackLayout>
<yummy:PancakeView
BackgroundGradientStartPoint="0,1"
BackgroundGradientEndPoint="1,0"
HeightRequest="240"
WidthRequest="320"
Padding="0,0,100,500"
HorizontalOptions="End"
CornerRadius="0,0,500,0">
<yummy:PancakeView.BackgroundGradientStops>
<yummy:GradientStopCollection>
<yummy:GradientStop Color="#155cab" Offset="0" />
<yummy:GradientStop Color="#1C75D8" Offset="0.5" />
<yummy:GradientStop Color="#589ce7" Offset="1" />
</yummy:GradientStopCollection>
</yummy:PancakeView.BackgroundGradientStops>
<Grid BackgroundColor="red" Margin="100,0,0,0" VerticalOptions="StartAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image
Grid.Row="0"
WidthRequest="100"
HeightRequest="100"
Source="UserLogin.png"
Margin="0,50,0,50"
/>
<StackLayout Grid.Row="1" BackgroundColor="Orange">
<Entry Placeholder="hello"/>
<Entry Placeholder="hello 1"/>
<Entry Placeholder="hello 2"/>
<Entry Placeholder="hello 3"/>
<Entry Placeholder="hello 4"/>
</StackLayout>
</Grid>
</yummy:PancakeView>
</StackLayout>
</yummy:PancakeView>
</ContentPage.Content>
i´m going to show the image (xaml file). please help me
enter image description here
You set the bottom padding to 500 in the second yummy:PancakeView is too big.I set it to 0 with following layout, it worked.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:yummy="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
x:Class="PanCakeView.MainPage">
<ContentPage.Content>
<yummy:PancakeView
BackgroundGradientStartPoint="0,1"
BackgroundGradientEndPoint="1,0"
Margin="0,0,0,10"
HorizontalOptions="FillAndExpand"
CornerRadius="0,0,400,0">
<yummy:PancakeView.BackgroundGradientStops>
<yummy:GradientStopCollection>
<yummy:GradientStop Color="#155cab" Offset="0" />
<yummy:GradientStop Color="#155cab" Offset="0.5" />
</yummy:GradientStopCollection>
</yummy:PancakeView.BackgroundGradientStops>
<StackLayout>
<yummy:PancakeView
BackgroundGradientStartPoint="0,1"
BackgroundGradientEndPoint="1,0"
HeightRequest="800"
WidthRequest="320"
Padding="0,0,100,0"
HorizontalOptions="End"
CornerRadius="0,0,500,0">
<yummy:PancakeView.BackgroundGradientStops>
<yummy:GradientStopCollection>
<yummy:GradientStop Color="#155cab" Offset="0" />
<yummy:GradientStop Color="#1C75D8" Offset="0.5" />
<yummy:GradientStop Color="#589ce7" Offset="1" />
</yummy:GradientStopCollection>
</yummy:PancakeView.BackgroundGradientStops>
<Grid BackgroundColor="red" Margin="100,0,0,0" VerticalOptions="StartAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image
Grid.Row="0"
WidthRequest="100"
HeightRequest="100"
Source="UserLogin.png"
Margin="0,50,0,50"
/>
<StackLayout Grid.Row="1" BackgroundColor="Orange">
<Entry Placeholder="hello"/>
<Entry Placeholder="hello 1"/>
<Entry Placeholder="hello 2"/>
<Entry Placeholder="hello 3"/>
<Entry Placeholder="hello 4"/>
</StackLayout>
</Grid>
</yummy:PancakeView>
</StackLayout>
</yummy:PancakeView>
</ContentPage.Content>
</ContentPage>
Here is running screenshot.
I am still pretty new to Xamarin Forms and I am having issues with displaying Material Design Icons for my app. I keep getting the box with question mark and I do not understand why. I am using a control template to create a header and footer for my page.
Heres the output on the screen:
View Display
Heres my App.xaml code:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="DueMore.App">
<Application.Resources>
<ResourceDictionary>
<Color x:Key="fgColor">#66169C</Color>
<Color x:Key="bgColor">#FFFFFF</Color>
<Color x:Key="OverDueItem">#FF1C07</Color>
<OnPlatform x:Key="Material" x:TypeArguments="x:String">
<On Platform="iOS" Value="Material Design Icons" />
<On Platform="Android" Value="materialdesignicons-webfont.ttf#Material Design Icons" />
</OnPlatform>
<Style TargetType="{x:Type Button}" x:Key="MaterialIcons">
<Setter Property="FontFamily" Value="{DynamicResource Material}"/>
<Setter Property="FontSize" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center"/>
<Setter Property="TextColor" Value="{DynamicResource fgColor}"/>
<Setter Property="FontSize" Value="Large"/>
</Style>
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="{DynamicResource bgColor}" />
<Setter Property="BarTextColor" Value="{DynamicResource fgColor}" />
</Style>
<ControlTemplate x:Key="MainPageTemplate">
<StackLayout>
<Grid Padding="5">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="1"
Grid.RowSpan="10"
Grid.Column="0"
Grid.ColumnSpan="5"/>
<Entry Placeholder="Enter an Inbox Item"
HeightRequest="50"
Grid.Column="0"
Grid.ColumnSpan="3"
Grid.Row="9"
BackgroundColor="{DynamicResource bgColor}"
TextColor="{DynamicResource fgColor}"
HorizontalOptions="Fill"/>
<Button Text=""
Style="{StaticResource MaterialIcons}"
Clicked="Save_Clicked"
Grid.Row="9"
Grid.Column="3"/>
<Button Text=""
Style="{StaticResource MaterialIcons}"
Clicked="Button_Clicked"
Grid.Row="9"
Grid.Column="4"/>
</Grid>
</StackLayout>
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
Any help would be appreciated! Thank you in advance!
On Android, you need to add the font icons to your Assets folder in your android platform specific project. On iOS, you need to add the font icons to the Resources folder in the iOS project.
ControlTemplate usage:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="App2.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
ControlTemplate="{StaticResource MainPageTemplate}"
mc:Ignorable="d">
<StackLayout>
<!-- Place new controls here -->
</StackLayout>
Screenshot:
For the source file with Material Design Icons, you could download from the GitHub.
https://github.com/WendyZang/Test/tree/master/MaterialDesignIcons/App2
I want change background image on every FlipView item.
I'm try this code, but it fired error Only IBehavior types are supported in a BehaviorCollection.
How set image source correctly?
<Grid>
<i:Interaction.Behaviors>
<core:DataTriggerBehavior
Binding="{Binding SelectedIndex, ElementName=TourFlipView}"
ComparisonCondition="Equal"
Value="1" />
<core:ChangePropertyAction
TargetObject="{Binding ElementName=TourFlipViewBackgroundImage}"
PropertyName="Source"
Value="ms-appx:///Assets/Images/2.png" />
</i:Interaction.Behaviors>
<Image
x:Name="TourFlipViewBackgroundImage"
Source="ms-appx:///Assets/Images/1.png" />
<FlipView
x:Name="TourFlipView">
...
<FlipView/>
</Grid>
You did almost correct with small mistake. put your ChangePropertyAction inside DataTriggerBehavior
<i:Interaction.Behaviors>
<core:DataTriggerBehavior
Binding="{Binding SelectedIndex, ElementName=TourFlipView}"
ComparisonCondition="Equal"
Value="1" >
<core:ChangePropertyAction
TargetObject="{Binding ElementName=TourFlipViewBackgroundImage}"
PropertyName="Source"
Value="ms-appx:///Assets/Images/2.png" />
</core:DataTriggerBehavior>
</i:Interaction.Behaviors>
I need to set the menuflyout to get right aligned. I used the code, but it appears at left only. Should I need to modify in the style?
<Button Content="Click" HorizontalAlignment="Right" Height="30" Width="30">
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyout.MenuFlyoutPresenterStyle>
<Style TargetType="MenuFlyoutPresenter">
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="MaxWidth" Value="50" />
<Setter Property="MaxHeight" Value="50" />
</Style>
</MenuFlyout.MenuFlyoutPresenterStyle>
<MenuFlyoutItem Text="Item" />
</MenuFlyout>
</Button.Flyout>
</Button>
From the screenshot, it seems you are develpoing a Windows Phone 8.1 app not a UWP app.
While using UWP, your code (I remove Height and Width in the Button) looks like:
I think this is what you want.
But in Windows Phone 8.1, we have to modify the template of MenuFlyoutPresenter to achieve this.
To modify the template of MenuFlyoutPresenter, we can select the "[MenuFlyout]" in "Document Outline" and right click, then select "Edit Additional Templates" → "Edit MenuFlyoutPresenterStyle" → "Edit a Copy...".
In the template, we need to set the HorizontalAlignment of OuterBorder, CenterBorder and InnerBorder to Right:
<Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" FlowDirection="LeftToRight" HorizontalAlignment="Right">
...
<Border x:Name="CenterBorder" BorderBrush="{TemplateBinding Background}" FlowDirection="LeftToRight" HorizontalAlignment="Right">
<StackPanel x:Name="InnerBorder" Background="{TemplateBinding Background}" FlowDirection="{TemplateBinding FlowDirection}" HorizontalAlignment="Right">
...
</StackPanel>
</Border>
</Border>
Then in the Button, we can use code like following:
<Button HorizontalAlignment="Right" Content="Click">
<Button.Flyout>
<MenuFlyout MenuFlyoutPresenterStyle="{StaticResource MenuFlyoutPresenterStyle1}" Placement="Bottom">
<MenuFlyoutItem Text="Item" />
</MenuFlyout>
</Button.Flyout>
</Button>
It looks like:
You can also change other properties in the Style of MenuFlyoutPresenter to beautify it.
Actually if you use default settings and set your Placement property of MenuFlyout, position should look fine. When I modify your code it should work properly as what you need. Yıu can check from screenshot.
<Button Content="Click" HorizontalAlignment="Right" Height="30" Width="114" Margin="0,200,0,0" VerticalAlignment="Top" >
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyoutItem Text="Item" HorizontalAlignment="Right" />
</MenuFlyout>
</Button.Flyout>
</Button>
I am tryng to add 2 new buttons to a document viewer control that us then hosted in a windows form, so I took the template from MSDN to modify, but the all the "inbuilt" standard buttons turn to text on display rather than the icons. I am wondering if anyone can please help me with why this happens and how to fix it as I have not been able to determine that from MSDN documentation. However I am a newbie to XAML. Below is the xaml for the modified control.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Documents="clr-namespace:System.Windows.Documents;assembly=PresentationUI" x:Class="AddinXPSViewer.XPSBrowser"
xmlns:self="clr-namespace:AddinXPSViewer"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
>
<Frame x:Name="DocFrame">
<Frame.Content>
<Grid>
<DocumentViewer x:Name="docViewer" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0,0,0,0" Unloaded="docViewer_Unloaded" Style="{DynamicResource DocumentViewerStyle}" ContextMenu="{x:Null}" >
<DocumentViewer.Resources>
<Style x:Key="DocumentViewerStyle" TargetType="DocumentViewer">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DocumentViewer">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ToolBar
ToolBarTray.IsLocked="True"
KeyboardNavigation.TabNavigation="Continue">
<Button Command="ApplicationCommands.Copy"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Copy"/>
<Separator />
<Button Command="NavigationCommands.IncreaseZoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Zoom In"/>
<Button Command="NavigationCommands.DecreaseZoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Zoom Out"/>
<Separator />
<Button Command="NavigationCommands.Zoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="100.0"
Content="Actual Size" />
<Button Command="DocumentViewer.FitToWidthCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Fit to Width" />
<Button Command="DocumentViewer.FitToMaxPagesAcrossCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="1"
Content="Whole Page"/>
<Button Command="DocumentViewer.FitToMaxPagesAcrossCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="2"
Content="Two Pages"/>
<Button Command="self:XPSBrowserCustomCommands.Next">Previous</Button>
<Button Command="self:XPSBrowserCustomCommands.Previous">Next</Button>
</ToolBar>
<ScrollViewer Grid.Row="1"
CanContentScroll="true"
HorizontalScrollBarVisibility="Auto"
x:Name="PART_ContentHost"
IsTabStop="true"/>
<ContentControl Grid.Row="2"
x:Name="PART_FindToolBarHost"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DocumentViewer.Resources>
<DocumentViewer.CommandBindings>
<CommandBinding Command="ApplicationCommands.Print" Executed="CommandBinding_OnPrint" />
<CommandBinding Command="ApplicationCommands.Print" CanExecute="CommandBinding_CanExecutePrint" />
<CommandBinding Command="self:XPSBrowserCustomCommands.Next" Executed="CommandBinding_OnPrevious" />
<CommandBinding Command="self:XPSBrowserCustomCommands.Next" CanExecute="CommandBinding_CanExecutePrevious" />
<CommandBinding Command="self:XPSBrowserCustomCommands.Previous" Executed="CommandBinding_OnNext" />
<CommandBinding Command="self:XPSBrowserCustomCommands.Previous" CanExecute="CommandBinding_CanExecuteNext" />
</DocumentViewer.CommandBindings>
</DocumentViewer>
</Grid>
</Frame.Content>
</Frame>
</UserControl>
The secret is to right click and edit the Template or a copy of the Template twice in visual studio, this gives a different template to the one on msdn, and access to the sub controls for the toolbar.
On each Button the Content property is set to a string value.
e.g. Content="Copy"
If you want it to be an image you will have to set it to an Image control.
e.g.
<Button>
<Image Source="copy.png"/>
</Button>
The 'default templates' on MSDN are not the actual default templates from WPF. They are just sample code for making your own control template.