Write message in text box with try catch on if - textbox

I would like a message to appear in a text box. The checked box indicates witch folder to copy to another directory. I would like a message to appear in the text box depending on if the copied folder as succeed or failed (error example : if the folder does not exist). At that point, i've tried with TRY CATCH, however, i can't figure out where to put my stuff so it wont erase the previous message or duplicate messages. Note, you can check UP TO 6 check boxes. So at the end i'm supposed to have 6 messages.
Look at Tab1BTNcreation at the bottom. Thank you !
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Add-Type -AssemblyName PresentationCore, PresentationFramework
[xml]$xaml = #"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Programme de tests QA" Height="515" Width="828" ResizeMode="NoResize">
<Grid>
<TabControl HorizontalAlignment="Left" Height="500" VerticalAlignment="Top" Width="825">
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Border Name="Border" BorderThickness="0,0,0,0" CornerRadius="5,5,0,0" Margin="2,0">
<ContentPresenter x:Name="Tab1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="10,2"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="#292929" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background" Value="#FF23BBB8" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabItem x:Name="tab1" Header="CR`ÉATION" Height="40" Width="273" Background="#292929" FontFamily="Segoe UI Semibold" Foreground="white" IsSelected="True">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4">
<Label x:Name="titre1" Content="cr`éation d'une nouvelle serie" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="440" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="440" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,121,0,0" TextWrapping="Wrap" Text="de" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,161,0,0" TextWrapping="Wrap" Text="vers" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBdeRep1" HorizontalAlignment="Left" Height="20" Margin="107,120,0,0" VerticalAlignment="Top" Width="103" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBdeSerie1" HorizontalAlignment="Left" Height="20" Margin="227,120,0,0" VerticalAlignment="Top" Width="211" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBversRep1" HorizontalAlignment="Left" Height="20" Margin="107,159,0,0" VerticalAlignment="Top" Width="103" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<TextBox x:Name="TBversSerie1" HorizontalAlignment="Left" Height="20" Margin="227,159,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="211" Padding="2" MaxLength="33" FontSize="10" Foreground="#797979" />
<Grid x:Name="CheckBoxGroup1">
<CheckBox x:Name="CBbin1" Content=" bin" HorizontalAlignment="Left" Height="19" Margin="480,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBexport1" Content=" export" HorizontalAlignment="Left" Height="19" Margin="480,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBparam1" Content=" param" HorizontalAlignment="Left" Height="19" Margin="480,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBlist1" Content=" list" HorizontalAlignment="Left" Height="19" Margin="600,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBscript1" Content=" script" HorizontalAlignment="Left" Height="19" Margin="600,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBtemplate1" Content=" template" HorizontalAlignment="Left" Height="19" Margin="600,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
</Grid>
<Button x:Name="BTNcreation" Content="cr`éer la s`érie et synchroniser" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
<TextBox x:Name="TBmessages1" HorizontalAlignment="Left" Height="145" Margin="55,238,0,0" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
</Grid>
</TabItem>
<TabItem x:Name="tab2" Header="SYNCHRONISATION" Background="#FF00565F" Height="40" Width="273" BorderBrush="#FF00565F" FontSize="12" Foreground="White" FontFamily="Segoe UI Semibold">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4">
<Label Content="synchronisation d'une s`érie" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="440" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="440" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,121,0,0" TextWrapping="Wrap" Text="de" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,161,0,0" TextWrapping="Wrap" Text="vers" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBdeRep2" HorizontalAlignment="Left" Height="20" Margin="107,120,0,0" VerticalAlignment="Top" Width="103" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBdeSerie2" HorizontalAlignment="Left" Height="20" Margin="227,120,0,0" VerticalAlignment="Top" Width="211" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBversRep2" HorizontalAlignment="Left" Height="20" Margin="107,159,0,0" VerticalAlignment="Top" Width="103" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBversSerie2" HorizontalAlignment="Left" Height="20" Margin="227,159,0,0" VerticalAlignment="Top" Width="211" FontSize="10" Foreground="#797979" />
<CheckBox x:Name="CBbin2" Content=" bin" HorizontalAlignment="Left" Height="19" Margin="480,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBexport2" Content=" export" HorizontalAlignment="Left" Height="19" Margin="480,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBparam2" Content=" param" HorizontalAlignment="Left" Height="19" Margin="480,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBlist2" Content=" list" HorizontalAlignment="Left" Height="19" Margin="600,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBscript2" Content=" script" HorizontalAlignment="Left" Height="19" Margin="600,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBtemplate2" Content=" template" HorizontalAlignment="Left" Height="19" Margin="600,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<TextBox x:Name="TBmessages2" HorizontalAlignment="Left" Height="145" Margin="55,238,0,0" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
<Button x:Name="BTNsynchro" Content="synchroniser la s`érie" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
</Grid>
</TabItem>
<TabItem x:Name="tab3" Header="EX`ÉCUTION" Background="#FF00565F" Height="40" Width="273" BorderBrush="#FF00565F" FontSize="12" Foreground="white" FontFamily="Segoe UI Semibold">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4" >
<Label x:Name="titre3" Content="ex`écution des tests QA" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="335" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="335" Y1="160" Y2="160" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="250" Y2="250" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="54,121,0,0" TextWrapping="Wrap" Text="version" VerticalAlignment="Top" Width="55" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="482,121,0,0" TextWrapping="Wrap" Text="`équipe" VerticalAlignment="Top" Width="55" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="482,161,0,0" TextWrapping="Wrap" Text="liste" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBversion3" HorizontalAlignment="Left" Height="20" Margin="113,120,0,0" VerticalAlignment="Top" Width="70" FontSize="10" Foreground="#797979" />
<TextBox x:Name="TBbuild3" HorizontalAlignment="Left" Height="20" Margin="201,120,0,0" TextWrapping="Wrap" Text="Build" VerticalAlignment="Top" Width="77" Padding="2" MaxLength="4" FontSize="10" Foreground="#797979" />
<TextBox x:Name="TBrevision3" HorizontalAlignment="Left" Height="20" Margin="297,120,0,0" TextWrapping="Wrap" Text="R`év." VerticalAlignment="Top" Width="36" Padding="2" MaxLength="3" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBequipe3" HorizontalAlignment="Left" Height="20" Margin="542,120,0,0" VerticalAlignment="Top" Width="150" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBliste3" HorizontalAlignment="Left" Height="20" Margin="542,159,0,0" VerticalAlignment="Top" Width="150" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<CheckBox x:Name="CBrtf3" Content=" produire les fichiers en format .rtf" HorizontalAlignment="Left" Height="19" Margin="480,217,0,0" VerticalAlignment="Top" Width="230" Foreground="#797979"/>
<TextBox x:Name="TBmessages3" HorizontalAlignment="Left" Height="190" Margin="55,193,0,0" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
<Button x:Name="BTNexecution" Content="lancer les tests" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
</Grid>
</TabItem>
</TabControl>
</Grid>
</Window>
"#
#Read XAML (Parse it)
$reader=(New-Object System.Xml.XmlNodeReader $XAML)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
#region ----- xaml objects to variables -----
#Connect to Controls TAB2
$Tab1CBB1 = $Window.FindName('CBBdeRep1')
$Tab1CBB2 = $Window.FindName('CBBdeSerie1')
$Tab1CBB3 = $Window.FindName('CBBversRep1')
$Tab1TB4 = $Window.FindName('TBversSerie1')
$Tab1CBbin = $Window.FindName('CBbin1')
$Tab1CBexport = $Window.FindName('CBexport1')
$Tab1CBparam = $Window.FindName('CBparam1')
$Tab1CBlist = $Window.FindName('CBlist1')
$Tab1CBscript = $Window.FindName('CBscript1')
$Tab1CBtemplate = $Window.FindName('CBtemplate1')
$Tab1TBmessages = $Window.findName("TBmessages1")
$Tab1BTNcreation = $Window.findName("BTNcreation")
$Tab1CBGroup = $Window.findName("CheckBoxGroup1")
#Connect to Controls TAB2
$Tab2CBB1 = $Window.FindName('CBBdeRep2')
$Tab2CBB2 = $Window.FindName('CBBdeSerie2')
$Tab2CBB3 = $Window.FindName('CBBversRep2')
$Tab2CBB4 = $Window.FindName('CBBversSerie2')
$Tab2CBbin = $Window.FindName('CBbin2')
$Tab2CBexport = $Window.FindName('CBbin2')
$Tab2CBparam = $Window.FindName('CBparam2')
$Tab2CBlist = $Window.FindName('CBlist2')
$Tab2CBscript = $Window.FindName('CBscript2')
$Tab2CBtemplate = $Window.FindName('CBtemplate2')
$Tab2TBmessages = $Window.findName("TBmessages2")
$Tab2BTNsynchro = $Window.findName("BTNsyncro")
#Connect to Controls TAB2
$Tab3CBBversion = $Window.findName("CBBversion3")
$Tab3TBbuild = $Window.findName("TBbuild3")
$Tab3TBrev = $Window.findName("TBrevision3")
$Tab3CBBequipe = $Window.findName("CBBequipe3")
$Tab3CBBliste = $Window.findName("CBBliste3")
$Tab3CBrtf = $Window.findName("CBrtf3")
$Tab3TBmessages = $Window.findName("TBmessages3")
$Tab3BTNexecution = $Window.findName("BTNexecution")
#endregion
#region ---- Path variables -----
$pathDE='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\'
$pathVERS='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\VERS\'
$pathDBQcust01='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\DBQcust01\Sets\'
$pathQA14='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA14\Sets\'
$pathQA15='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA15\Sets\'
$pathSERIE = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA14\Sets' #simulation
$pathSIMULATION = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation'
#endregion ----
#region ---- lists of series ----
$listQA14 = Get-ChildItem $pathQA14 -Directory -Name
$listQA15 = Get-ChildItem $pathQA15 -Directory -Name
$listDBQcust01 = Get-ChildItem $pathDBQcust01 -Directory -Name
$FolderLists = Get-ChildItem $pathSIMULATION\Listes -Include *.txt -Name
#endregion
#------------- TAB1 ------------------
#region /// ComboBox 1 : DE folder
$FoldersCBB1 = #('--- choisir ---','DBQcust01','QA14','QA15')
$Tab1CBB1.SelectedItem = '--- choisir ---'
foreach ($Folder in $FoldersCBB1) {
$Tab1CBB1.Items.Add($Folder)
}
#endregion
#region /// ComboBox 2 : DE SERIE (éventuellement changer pour SWITCH)
$Tab1CBB1.add_SelectionChanged({
$Selection = ($Tab1CBB1.SelectedItem.ToString())
if ($Selection -eq 'QA14')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous QA14 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous QA14 ---'
foreach ($Serie in $listQA14) {
$Tab1CBB2.Items.Add($Serie)
}
}
elseif ($Selection -eq 'QA15')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous QA15 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous QA15 ---'
foreach ($Serie in $listQA15) {
$Tab1CBB2.Items.Add($Serie)
}
}
elseif ($Selection -eq 'DBQcust01')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous DBQcust01 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous DBQcust01 ---'
foreach ($Serie in $listDBQcust01) {
$Tab1CBB2.Items.Add($Serie)
}
}
})
#endregion
#region /// ComboBox 3 : VERS folder
$FoldersCBB3 = #('SPMT','OTHER')
$Tab1CBB3.Items.Add('--- choisir ---')
$Tab1CBB3.SelectedItem = '--- choisir ---'
foreach ($Folder in $FoldersCBB3) {
$Tab1CBB3.Items.Add($Folder)
}
#endregion
#region /// TextBox 4 : VERS Série
#à venir (essayer de mettre le contenu des sélections des cbb automatiquement dans le textbox)
$Tab1TB4.text = "SÉRIE+ÉQUIPE"
#endregion
#region /// Bouton Creation
$Tab1BTNcreation.Add_Click({
$SelectionCBB1 = ($Tab1CBB1.SelectedValue)
$SelectionCBB2 = ($Tab1CBB2.SelectedValue)
$SelectionCBB3 = ($Tab1CBB3.SelectedValue)
$SelectionTB4 = ($Tab1TB4.Text)
$Tab1TBmessages.Clear()
New-item -ItemType Directory -Path "$pathVERS\$SelectionCBB3" -Name "$SelectionTB4"
$ErrorActionPreference = "stop"
If ($Tab1CBbin.IsChecked -eq $true) {
try {copy-item -Path "$pathDE\$SelectionCBB1\sets\$SelectionCBB2\Bin2" -Recurse -Destination "$pathVERS\$SelectionCBB3\$SelectionTB4",$Tab1TBmessages.AddText("Dossier Bin : Copié `r`n")}
catch {$Tab1TBmessages.AddText("Dossier Bin : Non copié `r`n")}
}
If ($Tab1CBexport.IsChecked -eq $true) {
try {copy-item -Path "$pathDE\$SelectionCBB1\sets\$SelectionCBB2\Export" -Recurse -Destination "$pathVERS\$SelectionCBB3\$SelectionTB4", $Tab1TBmessages.AddText("Dossier Export : Copié `r`n") }
catch {$Tab1TBmessages.AddText("Dossier Export : Non copié `r`n")}
}
If ($Tab1CBlist.IsChecked -eq $true) { copy-item -Path "$pathDE\$SelectionCBB1\sets\$SelectionCBB2\List" -Recurse -Destination "$pathVERS\$SelectionCBB3\$SelectionTB4" }
If ($Tab1CBparam.IsChecked -eq $true) { copy-item -Path "$pathDE\$SelectionCBB1\sets\$SelectionCBB2\Param" -Recurse -Destination "$pathVERS\$SelectionCBB3\$SelectionTB4" }
If ($Tab1CBscript.IsChecked -eq $true) { copy-item -Path "$pathDE\$SelectionCBB1\sets\$SelectionCBB2\QA\Script" -Recurse -Destination "$pathVERS\$SelectionCBB3\$SelectionTB4\QA\Script" }
If ($Tab1CBtemplate.IsChecked -eq $true) { copy-item -Path "$pathDE\$SelectionCBB1\sets\$SelectionCBB2\Template" -Recurse -Destination "$pathVERS\$SelectionCBB3\$SelectionTB4" }
else{
}
})
#endregion
#------------- TAB2 ------------------
#------------- TAB3 ------------------
$Window.ShowDialog() | out-null

Actually, i did this in my button (and will continue for all my IFs). I just copied the end of the code.
$Tab1BTNcreation.Add_Click({
$SelectionCBB1 = ($Tab1CBB1.SelectedValue)
$SelectionCBB2 = ($Tab1CBB2.SelectedValue)
$SelectionCBB3 = ($Tab1CBB3.SelectedValue)
$SelectionTB4 = ($Tab1TB4.Text)
$Tab1TBmessages.Clear()
$SelectedPathBin = "$pathDE\$SelectionCBB1\sets\$SelectionCBB2\Bin2"
$SelectedPathVers = "$pathVERS\$SelectionCBB3\$SelectionTB4"
New-item -ItemType Directory -Path "$pathVERS\$SelectionCBB3" -Name "$SelectionTB4"
If ($Tab1CBbin.IsChecked -eq $true) {
$TestPath1 = Test-Path $SelectedPathBin
$TestPath2 = Test-Path $SelectedPathVers
If ($TestPath1 -eq $True -and $TestPath2 -eq $True) {
copy-item -Path $SelectedPathBin -Recurse -Destination $SelectedPathVers
$Tab1TBmessages.AddText("Dossier Bin : Copié`r`n")
}
else {$Tab1TBmessages.AddText("Dossier Bin : Non copié `r`n")
}
} (......)

Related

Xamarin - Expander inside ListView not showing properly on iOs

Hello Im trying to use a Xamarin Toolkit Expander in a ViewCell of a ListView.
On android works as expected without any problem but on iOs looks like the ViewCell is not changing its size and the content of the expander is not usable.
It has a strange behaviour because if I scroll up enough to hide the header looks like the cell resizes itself and the content works fine but when clicking again the header the content hides but the cell keeps on the same size
Here is the xaml code
<ViewCell>
<Frame Margin="0,10,0,0" Padding="0">
<StackLayout Orientation="Horizontal" BackgroundColor="White" Padding="0">
<BoxView BackgroundColor="#FF9A31" HeightRequest="15" WidthRequest="15"/>
<behaviors:Expander Margin="10,0,10,0" HorizontalOptions="FillAndExpand" BackgroundColor="White" x:Name="Expander">
<behaviors:Expander.Header>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding NombreCliente}" FontSize="25" TextColor="Gray"/>
<Image Source="adultos.png" HeightRequest="20" Margin="20,0,0,0">
<Image.Triggers>
<DataTrigger TargetType="Image"
Binding="{Binding Source={RelativeSource AncestorType={x:Type behaviors:Expander}}, Path=IsExpanded}"
Value="True">
<Setter Property="IsVisible"
Value="False" />
</DataTrigger>
</Image.Triggers>
</Image>
<Label Text="{Binding PaxAdultos}" x:Name="AdultsHeaderText" FontSize="20" VerticalOptions="CenterAndExpand" TextColor="Gray">
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding Source={RelativeSource AncestorType={x:Type behaviors:Expander}}, Path=IsExpanded}"
Value="True">
<Setter Property="IsVisible"
Value="False" />
</DataTrigger>
</Label.Triggers>
</Label>
<Image Source="ninos.png" HeightRequest="20">
<Image.Triggers>
<DataTrigger TargetType="Image"
Binding="{Binding Source={RelativeSource AncestorType={x:Type behaviors:Expander}}, Path=IsExpanded}"
Value="True">
<Setter Property="IsVisible"
Value="False" />
</DataTrigger>
</Image.Triggers>
</Image>
<Label Text="{Binding PaxNinos}" x:Name="NinosHeaderText" FontSize="20" VerticalOptions="CenterAndExpand" TextColor="Gray">
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding Source={RelativeSource AncestorType={x:Type behaviors:Expander}}, Path=IsExpanded}"
Value="True">
<Setter Property="IsVisible"
Value="False" />
</DataTrigger>
</Label.Triggers>
</Label>
<Image Source="bebe.png" HeightRequest="20">
<Image.Triggers>
<DataTrigger TargetType="Image"
Binding="{Binding Source={RelativeSource AncestorType={x:Type behaviors:Expander}}, Path=IsExpanded}"
Value="True">
<Setter Property="IsVisible"
Value="False" />
</DataTrigger>
</Image.Triggers>
</Image>
<Label Text="{Binding PaxBebes}" x:Name="BebesHeaderText" FontSize="20" VerticalOptions="CenterAndExpand" TextColor="Gray">
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding Source={RelativeSource AncestorType={x:Type behaviors:Expander}}, Path=IsExpanded}"
Value="True">
<Setter Property="IsVisible"
Value="False" />
</DataTrigger>
</Label.Triggers>
</Label>
<Image HeightRequest="20" Source="arrow_down.png" HorizontalOptions="EndAndExpand">
<Image.Triggers>
<DataTrigger TargetType="Image"
Binding="{Binding Source={RelativeSource AncestorType={x:Type behaviors:Expander}}, Path=IsExpanded}"
Value="True">
<Setter Property="Source"
Value="arrow_up.png" />
</DataTrigger>
</Image.Triggers>
</Image>
</StackLayout>
</behaviors:Expander.Header>
<behaviors:Expander.Content>
<StackLayout Orientation="Vertical" Padding="0,10">
<StackLayout Orientation="Horizontal">
<Image Source="adultos.png" HeightRequest="25" Margin="30,0,0,0" />
<ImageButton Source="menos.png" WidthRequest="20" BackgroundColor="Transparent" Margin="44,0" x:Name="menosAdultos" Clicked="OnLessAdults" CommandParameter="{Binding .}"/>
<Label x:Name="nAdultsText" Text="{Binding PaxAdultos}" FontSize="20" TextColor="Gray" />
<ImageButton Source="mas.png" WidthRequest="20" HeightRequest="15" BackgroundColor="Transparent" Margin="44,0" x:Name="masAdultos" Clicked="OnMoreAdults" CommandParameter="{Binding .}"/>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="0,10,0,0">
<Image Source="ninos.png" HeightRequest="25" Margin="30,0,0,0"/>
<ImageButton Source="menos.png" WidthRequest="20" BackgroundColor="Transparent" Margin="44,0" x:Name="menosNinos" Clicked="OnLessKids" CommandParameter="{Binding .}"/>
<Label x:Name="nKidsText" Text="{Binding PaxNinos}" FontSize="20" TextColor="Gray"/>
<ImageButton Source="mas.png" WidthRequest="20" HeightRequest="15" BackgroundColor="Transparent" Margin="44,0" x:Name="masNinos" Clicked="OnMoreKids" CommandParameter="{Binding .}"/>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="0,10,0,0">
<Image Source="bebe.png" HeightRequest="25" Margin="30,0,0,0"/>
<ImageButton Source="menos.png" WidthRequest="20" BackgroundColor="Transparent" Margin="44,0" x:Name="menosBebes" Clicked="OnLessBabies" CommandParameter="{Binding .}"/>
<Label x:Name="nBabiesText" Text="{Binding PaxBebes}" FontSize="20" TextColor="Gray"/>
<ImageButton Source="mas.png" WidthRequest="20" HeightRequest="15" BackgroundColor="Transparent" Margin="44,0" x:Name="masBebes" Clicked="OnMoreBabies" CommandParameter="{Binding .}"/>
</StackLayout>
<Button x:Name="ConfirmarButton" FontSize="12" Text="CONFIRMAR CLIENTE" HorizontalOptions="Center" Padding="10,0" TextColor="White" BackgroundColor="Black" Margin="0,10,0,0" Clicked="ConfirmarButton_Clicked" CommandParameter="{Binding .}"/>
</StackLayout>
</behaviors:Expander.Content>
</behaviors:Expander>
</StackLayout>
</Frame>
</ViewCell>
Isn't it weird that on android works withou any problem but on iOs i am getting this weird behaviour?

UWPCommunityToolkit's PrintHelper produce blank output

I have my code below, basically to print out an image.
private async void imageControl_PrintButtonClick(object sender, RoutedEventArgs e)
{
var createBitmapTask = Task.Run(async () =>
{
var stream = await provider.OpenEntryAsRandomAccessStreamAsync(currentImageFile);
var decoder = await BitmapDecoder.CreateAsync(stream);
return await decoder.GetSoftwareBitmapAsync(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied);
});
var printHelper = new PrintHelper(printPanel);
printHelper.OnPreviewPagesCreated += PrintHelper_OnPreviewPagesCreated;
printPanel.Opacity = 1.0;
var source = new SoftwareBitmapSource();
var bitmap = await createBitmapTask;
await source.SetBitmapAsync(bitmap);
printImage.Source = source;
printFileName.Text = "Hello";
printImage.Height = bitmap.PixelHeight;
printImage.Width = bitmap.PixelWidth;
await printHelper.ShowPrintUIAsync("ZipPicView - " + currentImageFile.ExtractFilename(), true);
printPanel.Opacity = 0;
}
private void PrintHelper_OnPreviewPagesCreated(List<FrameworkElement> obj)
{
ContentDialog dialog = new ContentDialog();
}
However, the print preview shows an empty page. When I print it out, the printer does nothing.
I've tried changing the opacity of the printPanel (which is a Grid object) to non-zero, and the image does display on the screen. Still, the print has nothing on the output page.
I did notice that, on the OnPreviewPagesCreated, its obj parameter has a new object everytime it's called. The first call has one object with both Width and Height as NaN. My guess is because the container has no size, it cannot determine the content size.
Below is the XAML file.
<Page x:Name="page"
x:Class="ZipPicViewUWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ZipPicViewUWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"
mc:Ignorable="d" KeyUp="page_KeyUp" Loaded="page_Loaded" SizeChanged="page_SizeChanged">
<Canvas x:Name="canvas" SizeChanged="canvas_SizeChanged">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Height="1019" Width="1920">
<Grid x:Name="printPanel" Opacity="0">
<StackPanel x:Name="printContent"
Margin="0,0"
Orientation="Vertical">
<TextBlock x:Name="printFileName" />
<Image x:Name="printImage"
Stretch="Fill" />
</StackPanel>
</Grid>
<SplitView x:Name="splitView" DisplayMode="CompactOverlay" PanePlacement="Left" CompactPaneLength="50" OpenPaneLength="300">
<SplitView.Content>
<GridView x:Name="thumbnailGrid" />
</SplitView.Content>
<SplitView.Pane>
<Grid Background="{StaticResource SidebarBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<Button x:Name="subFolderButton" Width="50" Height="50" Background="Transparent" Click="subFolderButton_Click">
<SymbolIcon Symbol="List" />
</Button>
<TextBlock VerticalAlignment="Center" Margin="0,15">Folders</TextBlock>
</StackPanel>
<ScrollViewer Grid.Row="1">
<ListView x:Name="subFolderListCtrl" SelectionChanged="subFolderList_SelectionChanged" DataFetchSize="2" Margin="-10,0,0,0" />
</ScrollViewer>
<ProgressRing x:Name="thumbProgress" Height="30" Width="30" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="2" Margin="10,0,0,10" />
</Grid>
</SplitView.Pane>
</SplitView>
<interactivity:Interaction.Behaviors>
<behaviors:Blur x:Name="BlurBehavior" Duration="500" AutomaticallyStart="False" />
</interactivity:Interaction.Behaviors>
</Grid>
<Border x:Name="imageBorder" Visibility="Collapsed">
<Image x:Name="image" ManipulationMode="TranslateX" ManipulationCompleted="image_ManipulationCompleted" Tapped="image_Tapped">
<interactivity:Interaction.Behaviors>
<behaviors:Blur x:Name="ImageTransitionBehavior" Duration="500" AutomaticallyStart="False" />
</interactivity:Interaction.Behaviors>
</Image>
</Border>
<local:ViewerControl x:Name="imageControl" Visibility="Collapsed" CloseButtonClick="imageControl_CloseButtonClick" NextButtonClick="imageControl_NextButtonClick" PrevButtonClick="imageControl_PrevButtonClick" SaveButtonClick="imageControl_SaveButtonClick" PrintButtonClick="imageControl_PrintButtonClick" />
<Border x:Name="loadingBorder" Visibility="Collapsed">
<ProgressRing IsActive="True" Width="100" Height="100" />
</Border>
</Canvas>
<Page.TopAppBar>
<CommandBar VerticalContentAlignment="Center" VerticalAlignment="Center">
<CommandBar.Content>
<TextBlock Margin="10,0,0,0" x:Name="filenameTextBlock" Text="<None>" UseLayoutRounding="True" />
</CommandBar.Content>
<AppBarToggleButton x:Name="fullscreenButton" Icon="FullScreen" Label="FullScreen" Checked="fullscreenButton_Checked" Unchecked="fullscreenButton_Unchecked" />
<AppBarSeparator />
<AppBarButton x:Name="openFileButton" Icon="OpenFile" Label="Open File" Click="openFileButton_Click" />
<AppBarButton x:Name="openFolderButton" Icon="Folder" Label="Open Folder" Click="openFolderButton_Click" />
</CommandBar>
</Page.TopAppBar>
</Page>
And the source code is here : https://github.com/wutipong/ZipPicViewCS/tree/master/ZipPicViewUWP

ListBox in Grid not resize in SplitView

I have problem with resize gridlayout.
This is man page:
This page has ListBox in 3 column. But when I fill in the data my ListBox I don't see my buttons and scrollbar. I have ScrollBar in ScrollViewer but it doesn't work. I generate all values in For loop (100 items). For now I have something like this:
This is my code of page:
<Page
x:Class="MemoryWords.LernWords"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MemoryWords"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Name="mainPage">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width=".5*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Name="WordBeforeTranslation"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"/>
<StackPanel Grid.Column="1" >
<TextBlock Name="WordAfterTranslation"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"/>
<TextBlock Name="WordArticulation"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"/>
</StackPanel>
<ScrollViewer Grid.Column="2">
<ListBox Name="AllWords"/>
</ScrollViewer>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Content="Previous"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Button Grid.Column="1"
Content="Check"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Button Grid.Column="2"
Content="Next"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Name="BtnLoadFile"
Click="BtnLoadFile_Click"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Load file"/>
<Button Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="New Random"/>
<Button Grid.Column="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="--------"/>
</Grid>
</Grid>
</Page>
Next case:
How I can set on starting, my grid filled all content of page without loaded data to ListBox? And Can I resize my app without lost of content? I don't want set permanent values to height and width. I would like have only layouts without permanent values. Generally, I would like when I will rescale app, my grid will by have similar layout.
I would like to make my page look like as on first my screenshot.
Is it possible?
EDIT:
This is my code from MainPage:
<Page
x:Class="MemoryWords.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MemoryWords"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel>
<CommandBar HorizontalAlignment="Left">
<AppBarButton Label="Menu" Click="ToogleMenu_Click">
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Icon="Back" Label="Back" Click="GoBack_Click"/>
<AppBarButton Icon="Home" Label="Play" Click="GoHome_Click"/>
</CommandBar>
<!--<Button Content="Open" Click="Button_Click"/>-->
<SplitView Name="MySplitView"
DisplayMode="CompactOverlay"
CompactPaneLength="50"
OpenPaneLength="200">
<SplitView.Pane >
<StackPanel>
<ListBox SelectionMode="Single"
Name="ListOfMenu"
SelectionChanged="ListOfMenu_SelectionChanged">
<ListBoxItem Name="LearnWordsItem">
<StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets"
Text=""
FontSize="30"
MinWidth="50"/>
<TextBlock Text="Nauka słówek"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem Name="SettingItem">
<StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets"
Text=""
FontSize="30"
MinWidth="50"/>
<TextBlock Text="Ustawienia"/>
</StackPanel>
</ListBoxItem>
</ListBox>
</StackPanel>
</SplitView.Pane>
<SplitView.Content>
<StackPanel>
<Frame Name="MyFrame">
</Frame>
</StackPanel>
</SplitView.Content>
</SplitView>
</StackPanel>
</Page>
I saw that you've set three RowDefinition as "*", it certainly will drive out those buttons. If you want to make these buttons always show there, you need to set fixed height for the two rows. See the following code:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="100" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width=".5*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Name="WordBeforeTranslation"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20" />
<StackPanel Grid.Column="1">
<TextBlock Name="WordAfterTranslation"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20" />
<TextBlock Name="WordArticulation"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20" />
</StackPanel>
<ScrollViewer Grid.Column="2">
<ListBox Name="AllWords" />
</ScrollViewer>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Content="Previous"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
<Button Grid.Column="1"
Content="Check"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
<Button Grid.Column="2"
Content="Next"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Name="BtnLoadFile"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Load file" />
<Button Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="New Random" />
<Button Grid.Column="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="--------" />
</Grid>
</Grid>
Ok, I found answer on my question. :) Yeeee :)
My mistake was that in mainPage I didn't contained all in the grid.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<CommandBar Grid.Row="0" HorizontalAlignment="Left">
<AppBarButton Label="Menu" Click="ToogleMenu_Click">
<AppBarButton.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Icon="Back" Label="Back" Click="GoBack_Click"/>
<AppBarButton Icon="Home" Label="Play" Click="GoHome_Click"/>
</CommandBar>
<SplitView Grid.Row="1" Name="MySplitView"
DisplayMode="CompactOverlay"
CompactPaneLength="50"
OpenPaneLength="200"
VerticalAlignment="Stretch">
<SplitView.Pane >
<StackPanel>
<ListBox SelectionMode="Single"
Name="ListOfMenu"
SelectionChanged="ListOfMenu_SelectionChanged">
<ListBoxItem Name="LearnWordsItem">
<StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets"
Text=""
FontSize="30"
MinWidth="50"/>
<TextBlock Text="Nauka słówek"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem Name="SettingItem">
<StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets"
Text=""
FontSize="30"
MinWidth="50"/>
<TextBlock Text="Ustawienia"/>
</StackPanel>
</ListBoxItem>
</ListBox>
</StackPanel>
</SplitView.Pane>
<SplitView.Content>
<Frame Name="MyFrame" >
</Frame>
</SplitView.Content>
</SplitView>
</Grid>
Enough to change StackPanel on Grid. That is all.

Binding ContextMenu defined in a DataTemplate to command

Ok, here is my problem: I have a UserControl Template defined in Style.xaml like this
<Style x:Key="ModulProfTemplate" TargetType="{x:Type UserControl}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type UserControl}">
<Border BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true" BorderThickness="{TemplateBinding BorderThickness}" DataContext="{Binding DataContext, RelativeSource={RelativeSource TemplatedParent}}">
<Border x:Name="border" BorderBrush="#004E6CA9" BorderThickness="1.5">
<Grid x:Name="Layout" Background="{Binding Background, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0.5" DataContext="{Binding}">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Disponibil" Command="{Binding GridContextMenuCommand}" CommandParameter="disp"/>
<MenuItem Header="Indisponibil" Command="{Binding GridContextMenuCommand}" CommandParameter="indisp"/>
</ContextMenu>
</Grid.ContextMenu>
<Grid.RowDefinitions>
<RowDefinition Height="0.497*"/>
<RowDefinition Height="0.5*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" d:LayoutOverrides="Height" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock TextWrapping="Wrap" Text="{Binding SalaSaptPara, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="{Binding MaterieSaptPara, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock TextWrapping="Wrap" Text="{Binding SalaSaptImpara, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="{Binding MaterieSaptImpara, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,0,0,0"/>
</StackPanel>
</Grid>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="#CA4E6CA9"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
the problem is that i don't know how to bind the command to menuitem. The UserControl's DataContext is set to ViewModel.Luni.M1, and the command is in ViewModel DataContext. So my question is: How do i change the DataContext so i can bind the command?
Solved, all i had to do was add a tag to the border that was bound to my viewmodel's datacontext, and after that use PlacementTarget.Tag.MyCommand, as shown like this :)
<Border x:Name="border" BorderBrush="#004E6CA9" BorderThickness="1.5" Tag="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=my:CadreDidacticeView, AncestorLevel=1}, Path=DataContext}">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Header="Disponibil" Command="{Binding PlacementTarget.Tag.GridContextMenuCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}">
</MenuItem>
</ContextMenu>
</Border.ContextMenu>

Set the datacontext of the context menu with in a data template

Below is the code snippet:
<ResourceDictionary>
* * *
<DataTemplate x:Key="xyzTemplate" DataType="arguments" PresentationTraceSources.TraceLevel="High">
<StackPanel Orientation="Horizontal">
<TextBlock Text="(" VerticalAlignment="Center" Margin="2,0,2,0" FontSize="18"
x:Name="firstbrace" Visibility="Collapsed">
</TextBlock>
<ItemsControl ItemsSource="{Binding}" KeyboardNavigation.IsTabStop="False">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock
FontSize="11" VerticalAlignment="Bottom" Margin="1,0,1,2" Text=" , " Width="auto" Name="Comma" Height="auto" >
</TextBlock>
<ComboBox x:Name="blockCombo" Visibility="Collapsed" ItemsSource="{Binding XPath=.//value}" >
<ComboBox.ContextMenu>
<ContextMenu x:Name="xyzcontextMenu"
DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.DataContext}"
>
<MenuItem
Command="{Binding Path=xyzcommand}"
Header="MenuItem1" >
</MenuItem>
</ContextMenu>
</ComboBox.ContextMenu>
</ComboBox>
I need to set the data context of the context menu "xyzcontextmenu" as the data context of the UserControl.
Please let me know asap how can I achieve this
Thanks,
Shwetha

Resources