Set the button on top of the video streaming[WPF] - wpf

I use LibVLCSharp.WPF in a WPF application.
I want to put some icons and buttons above the video.
But after the VideoView control has loaded, it overwrite everything.
<Canvas Width="325" Height="182">
<Image Source="/Resource/BgLoading_1.png"
Width="325"
Height="182"
Stretch="Fill"
StretchDirection="Both"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Panel.ZIndex="0"
Visibility="Visible" />
<fa:ImageAwesome Foreground="White"
Icon="Spinner"
Spin="True"
Height="48"
Width="48"
Visibility="{Binding LoadImageStatus}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Canvas.Left="139"
Canvas.Top="67" />
<Image x:Name="imgLeftIcon"
Width="30"
Height="30"
Source="{Binding LeftIconSource}"
Stretch="Fill"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="10,10,10,10"
Visibility="{Binding LeftIconStatus}"
Panel.ZIndex="2" />
<Image x:Name="imgRightIcon"
Width="30"
Height="30"
Source="{Binding RightIconSource}"
Stretch="Fill"
Margin="285,10,10,142"
Visibility="{Binding RightIconStatus}"
Panel.ZIndex="2" />
<!--Video-->
<vlc:VideoView Grid.Row="0"
Height="182"
Width="325"
Visibility="{Binding VideoPlayerStatus}"
Panel.ZIndex="1" />
</Canvas>

RTFM
The controls that must appear on top of the video should be placed as children of the VideoView element.
<Window ...
xmlns:vlc="clr-namespace:LibVLCSharp.WPF;assembly=LibVLCSharp.WPF"
...>
<Grid>
<vlc:VideoView x:Name="VideoView">
<Button x:Name="PlayButton"
Click="PlayButtonOnClick"
Content="Play"
Margin="8"
HorizontalAlignment="Right"
VerticalAlignment="Bottom" />
</vlc:VideoView>
</Grid>
</Window>
Avoid Canvas since they are pretty dumb.
Working example sources based on the manual.

I haven't used vlc, if it covers the icons, I think it should be a window drawn with a separate handle. just like WindowsFormHost. try use Popup control, it can be displayed on top of any control.
<Grid>
<!--video control-->
<Grid Name="video">
<!--Video-->
<vlc:VideoView Grid.Row="0"
Height="182"
Width="325"
Visibility="{Binding VideoPlayerStatus}"
Panel.ZIndex="1" />
</Grid>
<Popup PlacementTarget="{Binding ElementName=video}" Placement="Center">
<Grid>
<Image x:Name="imgLeftIcon"
Width="30"
Height="30"
Source="{Binding LeftIconSource}"
Stretch="Fill"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="10,10,10,10"
Visibility="{Binding LeftIconStatus}"
Panel.ZIndex="2" />
</Grid>
</Popup>
</Grid>

Related

WPF Canvas as content inside button is not visible if adjacent element fills the space inside a container (DockPanel, Grid)

I have a button like so:
<StackPanel Orientation="Vertical" Width="200">
<DockPanel LastChildFill="False">
<Grid Width="81" Background="Blue" DockPanel.Dock="Right" />
<Button Width="120" DockPanel.Dock="Left">
<Grid>
<TextBlock Text="Button" ></TextBlock>
<Canvas Margin="120,0,0,0" >
<TextBlock Text="I want to break free" />
</Canvas>
</Grid>
</Button>
</DockPanel>
</StackPanel>
In this case the canvas content will not get rendered and it's content won't be visible.
If I however change the Grid lengths from 81 to 80 it works.
It will also work in this scenario:
<Grid Width="200">
<Grid Width="81" Background="Blue" DockPanel.Dock="Right" HorizontalAlignment="Right" Grid.Column="1" />
<Button Width="120" HorizontalAlignment="Left">
<Grid>
<TextBlock Text="Button" ></TextBlock>
<Canvas Margin="120,0,0,0" >
<TextBlock Text="I want to break free" />
</Canvas>
</Grid>
</Button>
</Grid>
The Canvas will also work if not inside a button:
<StackPanel Orientation="Vertical" Width="200">
<DockPanel LastChildFill="False" Height="42">
<Grid Width="81" Background="Blue" DockPanel.Dock="Right" />
<Canvas Margin="120,0,0,0" >
<TextBlock Text="I want to break free" />
</Canvas>
</DockPanel>
</StackPanel>
Why is it behaving like that inside a button? How can be this fixed to the wanted behavior of showing the canvas?

Make content inside Button responsive in WPF

I have vertical navigation bar. Each button of the navigation has it's own image and text. For now the image has static height set to Height="50"and text has the default value. When I resize the window the buttons grow responsive but the content inside keeps the same size.
This is how it look right now:
https://gyazo.com/48cff48437b66f462dccd23639dd59ac (GIF)
My XAML code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<UniformGrid Background="DodgerBlue" Grid.Column="1" Columns="1">
<Button BorderThickness="0" Background="DodgerBlue">
<StackPanel>
<Image Source="Icons/home-5-xxl.png" Height="50" Margin="0,0,0,10"/>
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Home</TextBlock>
</StackPanel>
</Button>
<Button BorderThickness="0" Background="DodgerBlue">
<StackPanel>
<Image Source="Icons/search-3-xxl.png" Height="50" Margin="0,0,0,10"/>
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Search</TextBlock>
</StackPanel>
</Button>
<Button BorderThickness="0" Background="DodgerBlue">
<StackPanel>
<Image Source="Icons/twitter-xxl.png" Height="50" Margin="0,0,0,10"/>
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Twitter</TextBlock>
</StackPanel>
</Button>
<Button BorderThickness="0" Background="DodgerBlue">
<StackPanel>
<Image Source="Icons/chat-4-xxl.png" Height="50" Margin="0,0,0,10"/>
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">Chat</TextBlock>
</StackPanel>
</Button>
</UniformGrid>
</Grid>
How could i make content inside the Buttons responsive and grow when the button grows in XAML WPF?
Use Viewbox as shown here.
<Viewbox Stretch="Uniform">
<Button ... />
</Viewbox>

Have image size to the window, but not the window to the image

I've been working on how to do layouts and I've come across something that is bugging the heck out of me. Now, if I use the code below, the window takes up the entirety of my screen.
<Window x:Class="HDD_Drill_View.Windows.WndwMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="HDDC"
WindowStartupLocation="CenterScreen"
Name="wndwMain"
Closing="WindowClosing"
ResizeMode="NoResize"
WindowState="Normal"
SizeToContent="WidthAndHeight">
<Grid>
<DockPanel Width="Auto"
LastChildFill="False"
HorizontalAlignment="Left">
<DockPanel.Background>
<ImageBrush ImageSource="..\Resources\background.png"
Stretch="UniformToFill"
TileMode="None" />
</DockPanel.Background>
<StackPanel DockPanel.Dock="Top"
Height="Auto"
Width="Auto"
Orientation="Horizontal"
HorizontalAlignment="Center">
<Button HorizontalAlignment="Left"
Name="bttnGenerateReports"
VerticalAlignment="Top"
UseLayoutRounding="False"
Click="BttnGenerateReportsClick"
Margin="10">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"><Run Text="Generate" /><LineBreak /><Run Text=" Reports" /></TextBlock>
</Button>
<Button HorizontalAlignment="Left"
Name="bttnSurveyReport"
VerticalAlignment="Top"
UseLayoutRounding="False"
Click="BttnSurveyReportClick"
Margin="10">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"><Run Text="Survey" /><LineBreak /><Run Text="Report" /></TextBlock>
</Button>
<Button HorizontalAlignment="Left"
Name="bttnTimeChart"
VerticalAlignment="Top"
UseLayoutRounding="False"
Click="BttnTimeChartClick"
Margin="10">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"><Run Text=" Time" /><LineBreak /><Run Text=" Chart" /></TextBlock>
</Button>
<Button HorizontalAlignment="Left"
Name="bttnMaterialAcquisition"
VerticalAlignment="Top"
UseLayoutRounding="False"
Click="BttnMaterialAcquisitionClick"
Margin="10">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"><Run Text=" Material" /><LineBreak /><Run Text="Acquistion" /></TextBlock>
</Button>
</StackPanel>
<StackPanel DockPanel.Dock="Bottom"
Height="Auto"
Width="Auto"
Orientation="Horizontal">
<!--MaxWidth="800"
MaxHeight="80"-->
<StackPanel.Background>
<ImageBrush ImageSource="..\Resources\drildata2.jpg" />
</StackPanel.Background>
</StackPanel>
</DockPanel>
</Grid>
</Window>
Yet, if I uncomment the Max Height and Max Width in the last StackPanel, then it seems fine. Basically, I'm wanting my background image to NOT affect my window size. Is this possible? I'm trying to set the background of a StackPanel to an image.
Remove the SizeToContent="WidthAndHeight" from the Window.

silverlight 5: force grid being in sync before screen-capture via writeablebitmap

In silverlight 5: I have built a product configurator that also constructs a drawing via combination of image's and Rectangle,Ellipse,Polygon constructions.
The configurator works fine and the drawing is fine as well. When a product is ready it's placed in a gallery (List box) and a thumbnail of the drawing is showing along with some main information. So far so good.
I can also save the configurations that are placed in the gallery to disc (xml) and load them later on to continue and finish. Here is the problem. I read the products one by one to the configurator, all business rules are in place then and the drawing takes place. But at the moment I save the product to the gallery the snapshot of the drawing stays blank.
I'm sure that all steps are fine because when I break at the point before placing the product in gallery, the drawing is showing correct. However, in the gallery the drawing is blank. So I assume a sync/timing/update problem but can't find a way to force redrawing of the grid that contains the images and drawings.
In axml, the listbox:
<ListBox x:Name="lbTiles" Loaded="lbTiles_Loaded" HorizontalAlignment="left" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Margin="2,2,0,0" Height="233" Width="892" d:LayoutOverrides="HorizontalAlignment" Background="Gainsboro" BorderThickness="2" BorderBrush="#FF606060">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel Orientation="Vertical" Background="Gainsboro">
<Border BorderThickness="1" BorderBrush="#4F000000" >
<Grid >
<Image Margin="0,0,0,0" Source="{Binding mImage, Mode=OneWay}" Stretch="Uniform" Height="110" ></Image>
</Grid>
</Border>
<TextBox TextAlignment="Center" IsReadOnly="True" Width="120" Height="23" Text="{Binding mName, Mode=OneWay}" IsHitTestVisible="False" IsTabStop="False" FontSize="11" />
<TextBox TextAlignment="Center" IsReadOnly="True" Width="120" Height="23" Text="{Binding mPrice, Mode=OneWay}" IsTabStop="False" IsHitTestVisible="False" FontSize="11" />
<TextBox TextAlignment="Center" IsReadOnly="True" Width="120" Height="23" Text="{Binding mTotal, Mode=OneWay}" IsHitTestVisible="False" IsTabStop="False" FontSize="11" />
<TextBox TextAlignment="Center" IsReadOnly="True" Width="120" Height="23" Text="{Binding mFreight, Mode=OneWay}" IsHitTestVisible="False" IsTabStop="False" FontSize="11" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The grid:
<Grid Name="myDrawing" Background="Gainsboro" Height="437" Width="486">
<Rectangle Name="clrFrame" Visibility="Collapsed" Margin="27,5,32,5" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
<Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL1" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
<Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL0" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
<Rectangle Name="clrWindow_1" Visibility="Collapsed" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
<Rectangle Name="clrWindow_2" Visibility="Collapsed" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
<Rectangle Name="clrWindow_3" Visibility="Collapsed" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
<Ellipse Name="clrWindow_4" Visibility="Collapsed" StrokeThickness="0" IsHitTestVisible="False" />
<Polygon Name="clrWindow_5" Visibility="Collapsed" StrokeThickness="18" IsHitTestVisible="False"></Polygon>
<Rectangle Name="clrDoor" Visibility="Collapsed" Margin="136,196,162,122" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
<Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL2" VerticalAlignment="Top" Width="429" IsHitTestVisible="False"/>
<Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL3" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
<Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL4" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
<Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL5" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
<Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL6" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
</Grid>
C# Code
for( int i = 0; i < count i++ )
{
xmlread al values to currentCasingComposition.....
writeToScreen(); // apply businessrules and do the drawing
myDrawing.InvalidateMeasure();
myDrawing.InvalidateArrange();
myDrawing.UpdateLayout();
// an exit here leaves me with the product in de confugurator and the drawing is fine
WriteableBitmap bmp = new WriteableBitmap(myDrawing, null); // capture drawing
currentCasingComposition.mImage = bmp;
currentCasingComposition.mImage.Invalidate();
currentCasingComposition.calculatePrice();
ocCasingCompositions.Add(currentCasingComposition); to gallery via ObservableCollection
}
Who knows the solution?
BR, Ton
UpdateLayout() is asynchronous on the UI thread, so you should wait for it to complete before calling the rest of the block. Unfortunately, I can find nothing on how to get notified when UpdateLayout() completes. All the examples that refer to it use a DispatcherTimer to wait a second or so before carrying on. So what I would do is create a one-off dispatcher timer, set its interval to 1000 milliseconds (or less, as needed) , and execute the rest of your code on it Tick event.

WPF Modal Window Transparency

I have created a modal WPF window that looks as follows:
Here is the code for the window:
<Window x:Class="Dionysus.Core.Controls.ModalWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ModalWindow" AllowsTransparency="True" Background="Transparent" WindowStyle="None">
<Grid Name="MainGrid">
<Rectangle Fill="Gray" Opacity="0.7" />
</Grid>
The "ErrorControl" is then added as follows:
MainGrid.Children.Add(uc);
The problem is as soon as I expand the stack trace, the controls transparency also changes:
I am assuming this has something to do with the ScrollViewer that uses the incorrect transparency, ie of the Rectangle instead of the containing Window.
I have also set the Opacity of the UserControl which owns the ScrollViewer to 1 and then binded the Opacity:
<ScrollViewer Background="WhiteSmoke" Opacity="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=Opacity}">
Can anyone help me?
--
UPDATE
Here is the code for the UserControl that is inserted into the Window
<Grid x:Name="LayoutRootx" Background="WhiteSmoke">
<StackPanel VerticalAlignment="Stretch">
<TextBlock TextWrapping="Wrap" Margin="5" Text="An error has occured:" Foreground="Black" FontSize="15" FontWeight="Medium"/>
<TextBlock TextWrapping="Wrap" Margin="5,10,5,5" Text="{Binding Error}"/>
<odc:OdcExpander Header="Stack Trace" Margin="5" IsExpanded="False" Background="WhiteSmoke">
<TextBox Text="{Binding StackTrace}" TextWrapping="Wrap" Margin="5,10,5,5" IsReadOnly="True" MaxHeight="370"/>
</odc:OdcExpander>
<odc:OdcExpander Header="Comment" Margin="5" IsExpanded="False">
<TextBox Text="{Binding Comment}" TextWrapping="Wrap" Margin="5,10,5,5" MaxHeight="370" Name="txtComment"/>
</odc:OdcExpander>
<StackPanel Margin="5,10,5,5" Orientation="Horizontal" HorizontalAlignment="Left">
<Button Style="{StaticResource DionysusButton}" Width="100" Height="23" IsDefault="True" Name="btnSendError">
<StackPanel Orientation="Horizontal">
<Image Source="/Dionysus.Shell;component/Images/camera-icon.png" Margin="0,0,5,0">
</Image>
<TextBlock Text="Send to IT" VerticalAlignment="Center"/>
<core:DionysusTriggerAction Height="0" Width="0" TargetControl="{Binding ElementName=btnSendError}" MethodName="SendError"></core:DionysusTriggerAction>
</StackPanel>
</Button>
<Button Style="{StaticResource DionysusButton}" Width="100" Height="23" Name="btnExit" Margin="10,0,0,0" IsCancel="True">
<StackPanel Orientation="Horizontal">
<Image Source="/Dionysus.Shell;component/Images/DeleteRed.png" Margin="0,0,5,0">
</Image>
<TextBlock Text="Close" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<core:DionysusTriggerAction Height="0" Name="triggerAction2" Width="0" TargetControl="{Binding ElementName=btnExit}" MethodName="Exit"></core:DionysusTriggerAction>
</StackPanel>
</StackPanel>
</Grid>
If your window has a fixed size and cannot be resized, you can use the following trick:
<Grid>
<Border BorderThickness="100" BorderBrush="Gray" Opacity="0.7">
<Grid Background="White" Grid.Column="1" Grid.Row="1" x:Name="contentPlaceHolder">
<TextBlock Text="HELLO WORLD" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Border>
</Grid>
However, it is unlikely that your Window will always have the same size, so to make it more dynamic, you could change the layout of the Window as follows:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="YourDesiredSize"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="YourDesiredSize"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Rectangle Fill="Gray" Opacity="0.7" Grid.Row="0" Grid.ColumnSpan="3"/>
<Rectangle Fill="Gray" Opacity="0.7" Grid.Row="2" Grid.ColumnSpan="3"/>
<Rectangle Fill="Gray" Opacity="0.7" Grid.Row="1" Grid.Column="0"/>
<Rectangle Fill="Gray" Opacity="0.7" Grid.Row="1" Grid.Column="2"/>
<Grid Grid.Column="1" Grid.Row="1" Background="White" x:Name="contentPlaceHolder">
<TextBlock Text="HELLO WORLD" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Grid>
The result of this window placed on top of another looks more or less like this:
and then instead of adding to the MainGrid, add the UserControl to the contentPlaceHolder or however you want to call it:
contentPlaceHolder.Children.Add(uc);
Okay so I found a solution that works for me, I'm sure it's not the best but it might help someone having the same problem as I did.
The problem was that controls within my UserControl that I added to my Window were transparent, although I could not figure out the reason, I found a simple workaround.
By changing the OpacityMask property of the UserControl to whatever the required Background colour is, even if the controls opacity changes, it will be masked with the Brush that you supply.
uc.OpacityMask = Brushes.WhiteSmoke;
Hope it helps someone!

Resources