I have tried hard to host an ActiveX control in Flipview but have been unable to achieve desired result. I'm using Windows 7 and Flipview control, as found on codeproject (http://www.codeproject.com/Articles/741026/WPF-FlipView). I'm actually embedding a flash movie into my project, and on swiping the new movie should be loaded.
<UserControl x:Class="MTC.SIMVA.IC.Controls.WPFFlashControl"
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:fla="clr-namespace:AxShockwaveFlashObjects;assembly=AxInterop.ShockwaveFlashObjects"
mc:Ignorable="d" Loaded="UserControl_Loaded" >
<DockPanel Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
<WindowsFormsHost x:Name="flashMovie">
<fla:AxShockwaveFlash x:Name="flashMovie2" />
</WindowsFormsHost>
</DockPanel>
</UserControl>
I have also made custom control to wrap AxShockwaveFlash control. My view is as follows:
<dl:FlipView x:Name="flipView" ItemsSource="{Binding Flows}" SelectedIndex="0" SelectionChanged="flipView_SelectionChanged">
<dl:FlipView.DataContext>
<vm:SwipeWinViewModel />
</dl:FlipView.DataContext>
<dl:FlipView.ItemTemplate>
<DataTemplate>
<DockPanel x:Name="mainPanel" LastChildFill="True">
<DockPanel x:Name="topPanel" DockPanel.Dock="Top" HorizontalAlignment="Left" VerticalAlignment="Top" Background="#E4E4E4" Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DockPanel}}}">
<DockPanel LastChildFill="True" Height="80">
<TextBlock Text="{Binding Name}" FontFamily="Segoe UI" VerticalAlignment="Center" Block.TextAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" FontWeight="Bold" FontSize="22" Margin="200,0,200,0" />
</DockPanel>
</DockPanel>
<DockPanel x:Name="animPanel" Background="LightBlue" Visibility="Collapsed" Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DockPanel}}}">
<uc:WPFFlashControl x:Name="flashControl" MovieSource="{Binding Source}"/>
</DockPanel>
</DockPanel>
</DataTemplate>
</dl:FlipView.ItemTemplate>
</dl:FlipView>
A window is displayed but nothing is shown. However, when I use custom control without FlipView it works fine, so I think there is problem with FlipView Control. Is it possible to use such custom control in datatemplate of FlipView control?
Related
I have a usercontrol that is surrounded with a bordercontrol. What I want is that I can set the borderbrush through a property when I am placing the control. I can set the color of the border but the problem is that the cornerradius is not working. The only way it works is if I set the borderbrush in the usercontrol itself.
Evertything else is working just fine. I can set the text properties for the labels and the image property for the Image but I cannot find out why the cornerradius is not working.
<UserControl x:Class="CoinManager.Controls.AltCoinButton"
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:local="clr-namespace:CoinManager.Controls"
mc:Ignorable="d"
d:DesignHeight="80" Width="80">
<Border Name="crtBorder"
BorderThickness="1"
Padding="5"
CornerRadius="5"
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}">
<Grid>
<StackPanel HorizontalAlignment="Center">
<Image Source="{Binding Path=ImageSource, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}"
Height="25" Width="25"
/>
<Label Content="{Binding Path=ContentCoinType, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}"
Foreground="#FAFAFA"
HorizontalContentAlignment="Center" Margin="0,5,0,0"
FontFamily="Segoe UI"/>
<Label Content="{Binding Path=ContentCoinValue, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}"
Foreground="#FAFAFA"
HorizontalContentAlignment="Center" Margin="0,-10,0,0"
FontFamily="Segoe UI"/>
</StackPanel>
</Grid>
</Border>
Here is the code in my custom project.
<Controls:AltCoinButton x:Name="btcButton"
Height="80"
Width="80" ImageSource="{StaticResource BtcLogo}"
BorderBrush="#FF9900"
ContentCoinType="Bitcoin"
ContentCoinValue="€ 1544,23"
HorizontalAlignment="Left"
Margin="186,50.254,0,0"
VerticalAlignment="Top" d:LayoutOverrides="Width, Height"/>
Can anyone of you help me out?
I found the solution. It turned out I had implemented the wrong relative for the borderbrush source. In stead of:
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}">
It should have been:
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType=local:AltCoinButton, AncestorLevel=1}}">
<TabControl HorizontalAlignment="Stretch" TabStripPlacement="Left" Margin="10,20,0,0" Name="tabControl2" ItemsSource="{Binding NotesObs}" VerticalAlignment="Stretch" MinHeight="80">
<TabItem Header="Contract Read and understood, proposal letter read and understood." Name="tabItem2" FontSize="14" IsEnabled="True">
<Grid>
<Border Name="b_desc"/>
<TextBox HorizontalAlignment="Stretch" Margin="0" Name="textBox5" Text="{Binding ContractText}"
VerticalAlignment="Stretch" FontSize="12" TextWrapping="Wrap"
AutoWordSelection="True" VerticalScrollBarVisibility="Auto"
AcceptsReturn="True"
Width="{Binding ElementName=b_desc, Path=ActualWidth}"
Height="{Binding ElementName=b_desc, Path=ActualHeight}"
MaxWidth="{Binding ElementName=b_desc, Path=Width}"
MaxHeight="{Binding ElementName=b_desc, Path=Height}" />
</Grid>
</TabItem>
</TabControl>
Above is my Xaml and the name of my ObsCollection is
public ObservableCollection<NotesDisplay> NotesObs { get; set; }
I have declared properly the ContractText column in the NotesDisplay Model. I cant get this to bind for some reason but this works in a datagrid. Can someone explain what I am doing wrong in my XAML?
Thanks
Edit: I have viewed the linked solution but tabs arent showing up when I run the program. They do showup in the display in xaml
<UserControl x:Class="CAT_Application_WPF.UI.NotesPage"
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:local="clr-namespace:CAT_Application_WPF.UI"
xmlns:viewModel="clr-namespace:CAT_Application_WPF.ViewModel"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d"
xmlns:oxy="http://oxyplot.org/wpf"
d:DesignHeight="640">
<Grid Margin="0,0,0,0" Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" d:DataContext="{d:DesignInstance viewModel:NotesPageViewModel}" >
<Grid.RowDefinitions>
<RowDefinition Height="60*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"></ColumnDefinition>
<ColumnDefinition Width="400"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TabControl HorizontalAlignment="Stretch" ItemsSource="{Binding NotesObs}" TabStripPlacement="Top" x:Name="_tabControl" VerticalAlignment="Stretch" MinHeight="80" Grid.ColumnSpan="2" Margin="121,28,279,-28">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock Text="{Binding ContractText}"/>
</TextBlock>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<TextBlock>
This is <TextBlock Text="{Binding EMSText}"/>
</TextBlock>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Grid>
</UserControl>
Now it's quite ok but you must remove your TextBlock inside another TextBlock stuff.
You can change
<TextBlock>
<TextBlock Text="{Binding ContractText}"/>
</TextBlock>
to
<TextBlock Text="{Binding ContractText}"/>
And
<TextBlock>
This is <TextBlock Text="{Binding EMSText}"/>
</TextBlock>
to something similar to
<StackPanel Orientation="Horizontal">
<TextBlock>This is</TextBlock>
<TextBlock Text="{Binding EMSText}"/>
</StackPanel>
I am developing wpf application with MvvmCross. I have my own dialog plugin that has a alert window. It will pop up when I click on some buttons to confirm my action. Previously, alert window is just a simple wpf window. But I want to use Mahapps to style it.
The problem is when I changed the base class of AlertWindow from window to Mahapps's MetroWindow an error has occurred "Could not find plugin type in assembly"
Below is my code in xaml file and c# file
<Controls:MetroWindow x:Class="Test.MvvmCross.Plugins.Dialog.Wpf.AlertWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="" Height="120" Width="350" SizeToContent="Height" ShowInTaskbar="False" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" >
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Test.MvvmCross.Plugins.Dialog.Wpf;component/Styles/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" Margin="10" Text="{Binding Message}" Name="MessageTb">asdfasdf asdfasdf asdfa asdfas asdf asdf asdf</TextBlock>
<DockPanel Margin="5" Background="White">
<Button DockPanel.Dock="Right" Margin="5" Height="30" Width="65" Name="NeutralButton" IsCancel="True">
<Grid>
<ContentControl Style="{StaticResource Content1NormalButtonStyle}" >
<TextBlock Name="NeutralContent1Textblock" Foreground="{StaticResource ButtonNotSelectedColorBrush}"/>
</ContentControl>
<ContentControl Style="{StaticResource Content2NormalButtonStyle}" >
<TextBlock Name="NeutralContent2Textblock" Foreground="{StaticResource ButtonTextColorBrush}" FontWeight="Bold"/>
</ContentControl>
</Grid>
</Button>
<Button DockPanel.Dock="Right" Margin="5" Height="30" Width="65" Name="NegativeButton">
<Grid>
<ContentControl Style="{StaticResource Content1NormalButtonStyle}" >
<TextBlock Name="NegativeContent1Textblock" Foreground="{StaticResource ButtonNotSelectedColorBrush}"/>
</ContentControl>
<ContentControl Style="{StaticResource Content2NormalButtonStyle}" >
<TextBlock Name="NegativeContent2Textblock" Foreground="{StaticResource ButtonTextColorBrush}" FontWeight="Bold"/>
</ContentControl>
</Grid>
</Button>
<Button DockPanel.Dock="Right" Margin="5" Height="30" Width="65" Name="PositiveButton" IsDefault="True" >
<Grid>
<ContentControl Style="{StaticResource Content1NormalButtonStyle}" >
<TextBlock Name="PositiveContent1Textblock" Foreground="{StaticResource ButtonNotSelectedColorBrush}"/>
</ContentControl>
<ContentControl Name="PositiveContent2" Style="{StaticResource Content2NormalButtonStyle}" >
<TextBlock Name="PositiveContent2Textblock" Foreground="{StaticResource ButtonTextColorBrush}" FontWeight="Bold"/>
</ContentControl>
</Grid>
</Button>
<Control />
</DockPanel>
</StackPanel>
</Controls:MetroWindow>
This is the and error message image.
**I have updated the xaml code
I have used Mahapps in my main project with no problem. Please let me know if you not understand what i want or anything else.
I found the solution of my problem. It is the version of MahApps. Because the ui project use an older version than the plugin project.
After I changed them to be same, everything is fine.
I've searched and read anything I can about ContextMenus and binding, and how it's not in the tree... etc. So searching feels like I've exhausted it and just don't understand it.
I'm trying to get my ContextMenu AddTournamentCommand to work, but I simply can't get it to command. I recently found out the easy way through Data Sources to bind to objects, so if there's an easy way other than coding it by hand to wire it up, please let me know. This is what I have so far:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Models="clr-namespace:FumbblApiClient.Models" mc:Ignorable="d" x:Name="FumbblMainWindow" x:Class="FumbblApiClient.MainWindow"
Title="MainWindow" Height="499.45" Width="639" Loaded="Window_Loaded">
<Window.Resources>
<CollectionViewSource x:Key="groupViewSource" d:DesignSource="{d:DesignInstance {x:Type Models:Group}, CreateList=True}"/>
<CollectionViewSource x:Key="groupTournamentsViewSource" Source="{Binding Tournaments, Source={StaticResource groupViewSource}}"/>
</Window.Resources>
<Grid Margin="0,0,2,0">
<TabControl Margin="10">
<TabItem Header="Groups">
<Grid Background="#FFE5E5E5" DataContext="{StaticResource groupViewSource}">
<TextBox x:Name="GroupIdTextBox" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" Text="Group ID" VerticalAlignment="Top" Width="100" Grid.Column="1"/>
<Button Content="Fetch" HorizontalAlignment="Left" Margin="115,11,0,0" VerticalAlignment="Top" Width="61" Click="GroupFetch_Click" Grid.Column="1" Height="22"/>
<ListBox x:Name="groupListView" ItemsSource="{Binding}" Margin="10,38,0,10" SelectionMode="Single" HorizontalAlignment="Left" Width="166" SelectionChanged="GroupList_SelectionChanged">
</ListBox>
<Grid x:Name="grid1" Margin="181,38,10,0" VerticalAlignment="Top" Height="369">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Id:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBox x:Name="idTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding Id, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="Name:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="1" VerticalAlignment="Center"/>
<TextBox x:Name="nameTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="1" Text="{Binding Name, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="Tournaments:" HorizontalAlignment="Left" Margin="3" Grid.Row="2" VerticalAlignment="Center"/>
<ListBox x:Name="tournamentsListView" ItemsSource="{Binding Source={StaticResource groupTournamentsViewSource}}" Margin="3,3,-182,-260" SelectionMode="Multiple" Grid.Row="2" Grid.Column="1">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="UIElement.PreviewMouseRightButtonDown" Handler="EmptyHandler"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Add To Selected Tournaments" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=PlacementTarget.DataContext.AddTournamentCommand}"/>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
</Grid>
</Grid>
</TabItem>
<TabItem Header="Tournaments">
<Grid Background="#FFE5E5E5" Margin="0,0,0,-2">
<ListBox HorizontalAlignment="Left" Margin="10,10,0,10" Width="166"/>
</Grid>
</TabItem>
<TabItem Header="Teams">
</TabItem>
<Grid Margin="0,0,-10,10"/>
</TabControl>
</Grid>
</Window>
and in the Code Behind:
public partial class MainWindow : Window
{
[removed]
private ICommand addTournamentCommand;
public ICommand AddTournamentCommand
{
get
{
if(addTournamentCommand == null)
{
addTournamentCommand = new RelayCommand(OnTournamentAdded);
}
return addTournamentCommand;
}
}
private void OnTournamentAdded(object state)
{
}
}
PlacementTarget property is on Context Menu and not on window. Travel to ContextMenu and not to Window. Window anyhow doesn't lies in Visual Tree of ContextMenu so you can't reach to it using RelativeSource.
<ContextMenu>
<MenuItem Header="Add To Selected Tournaments"
Command="{Binding RelativeSource={RelativeSource
AncestorType={x:Type ContextMenu}},
Path=PlacementTarget.DataContext.AddTournamentCommand}"/>
</ContextMenu>
With above code you will get PlacementTarget's dataContext which will be ListBox's DataContext and if you haven't set explicitly DataContext on ListBox, it will inherit it from Window and your code will work fine.
UPDATE
You can store the Window DataContext in Tag of ListBox and bind with it.
<ListBox Tag="{Binding DataContext,
RelativeSource={RealtiveSource Mode=FindAncestor,
AncestorType=Window}}"/>
and in ContextMenu bind using Tag:
<ContextMenu>
<MenuItem Header="Add To Selected Tournaments"
Command="{Binding RelativeSource={RelativeSource
AncestorType={x:Type ContextMenu}},
Path=PlacementTarget.Tag.AddTournamentCommand}"/>
</ContextMenu>
Change like this,
<ContextMenu>
<MenuItem Header="Add To Selected Tournaments" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=AddTournamentCommand}"/>
</ContextMenu>
<Grid>
<Canvas>
<TextBox Name="txt" IsReadOnly="True" Width="620" VerticalAlignment="Center"
Canvas.Left="340" Canvas.Top="5" Text="{Binding RowTitle2,Mode=OneWay}"
ToolTipService.ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}"
TextWrapping="NoWrap" HorizontalAlignment="Stretch"/>
</Canvas>
</Grid>
this way there is no tooltip, so how to add one ?
here i create dynamically records(txtboxes in the grid)
but on a similar example everything works just fine(no dynamilcall creation of txtboxes)
<Grid>
<Canvas>
<TextBox Name="txt" Margin="0,5,5,0" IsReadOnly="True" Width="620" VerticalAlignment="Center"
Canvas.Left="-200" Canvas.Top="-5"
ToolTipService.ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}"
TextWrapping="NoWrap" HorizontalAlignment="Stretch"/>
</Canvas>
</Grid>
What's the point here ? Its a bit confusing to use ReadOnly text box in a canvas which is located in a grid. Instead use a TextBlock which also improves performance, prevents memory leak, and looks better.
<Grid>
<TextBlock Margin="0,5,5,0"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
TextWrapping="NoWrap"
Text="{Binding RowTitle2}"
ToolTipService.ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}"
/>
</Grid>