I am looking to create a slider bar like this: slider bar with 2 thumbs In c# on Avalonia
I tried this:
<Slider Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0, 0, 65, 0" Height="35" Width="150" Minimum="0" Maximum="100" Value="50" />
But it's for a single thumb
Related
I'm working on a chat client and I'm having a bit of trouble making it look pretty. I have a polygon defined as this:
<Polygon
Points="0,25 5,27 5,35 200,35 200,15 5,15 5,23 0,25"
Stroke="Purple"
Margin="4, 0, 4, 0">
<Polygon.Fill>
<SolidColorBrush Color="#e4eef2" />
</Polygon.Fill>
</Polygon>
This polygon makes a chat message window similar to the one Skype uses.
A textblock is used directly below it to display the text.
<TextBlock FontSize="14" Width="auto" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="12, 0, 4, 0" TextWrapping="WrapWithOverflow" Text="{Binding text}"/>
If the text is too long and wraps, it falls outside of the polygon. Also, there may be multi-line text, which also falls outside of the polygon. Finally, I'm having trouble getting the polygon to extend the full width of the listitem it is contained in.
The full code is below.
<ListBox Grid.Column="2" Name="MessageList" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <!-- Messages -->
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" LastChildFill="True">
<Image Visibility="{Binding visibility}" Height="50" Width="50" Stretch="Fill" Source="sampleavatar.png"/>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Polygon
Points="0,25 5,27 5,35 200,35 200,15 5,15 5,23 0,25"
Stroke="Purple"
Margin="4, 0, 4, 0">
<Polygon.Fill>
<SolidColorBrush Color="#e4eef2" />
</Polygon.Fill>
</Polygon>
<TextBlock FontSize="14" Width="auto" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="12, 0, 4, 0" TextWrapping="WrapWithOverflow" Text="{Binding text}"/>
</Grid>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How a message should look, except it should be more centered
Even less centered text when there's no avatar
Text wrapping, also notice the polygon doesn't shrink horizontally(Nor does it grow horizontally when the listboxitem is bigger)
What you can do, is use a combination of Polygons and a TextBox (read only) to achieve what you want.
The key point here is you want the polygon to grow whenever the text grows/wraps. So to get this to work, we can use a TextBox's border, and a combination of polygons to get the triangle.
See below:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Polygon Grid.Column="0"
x:Name="Polygon"
Points="8,0 0,5, 8,10"
Stroke="Purple"
Fill="#e4eef2"
StrokeThickness="2"
VerticalAlignment="Center"
Margin="2,2,-4,0"/>
<Polygon Grid.Column="1"
Panel.ZIndex="10"
Points="8,0 0,5, 8,10"
Stroke="#e4eef2"
Fill="#e4eef2"
StrokeThickness="2"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="-2.5,2,0,0"/>
<TextBox Grid.Column="1"
Background="#e4eef2"
BorderBrush="Purple"
BorderThickness="2,2,2,2"
VerticalAlignment="Center"
Padding="8,0,8,0"
FontSize="14"
Width="auto"
TextWrapping="WrapWithOverflow"
Text="This is a test"
IsReadOnly="True"/>
</Grid>
Your polygon is not going to shrink horizontally with the text because that is actually a different polygon, I think an option is to scale the polygon horizontally or vertically or both which might require some IValueConverters.
Start with this,
<Border VerticalAlignment="Center" BorderThickness="0,1,1,1" BorderBrush="Purple" CornerRadius="5">
<TextBlock x:Name="textBlock"
FontSize="14" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="12, 0, 0, 0" TextWrapping="WrapWithOverflow" Text="blah blah blah blah blah blah blah blah blah "/>
</Border>
Then add your curly thing to the left side.
I am working with WPF, and what I want to do is to set opacity and background color of my button but I dont want to affect content inside my button. I tried few ways but unfortunately that did not work.
I found this style and I would like to apply something like that:
This is my numeric keyboard: ( I AM TRYING TO EDIT BTN 7) :
As you can see guys, unfortunately I could not set opacity of my button without affecting the content inside.
Here is my XAML code (focus on btn 7):
<StackPanel Height="50" Orientation="Horizontal" Margin="0,0,0,5">
<Button FontSize="15" FontWeight="Bold" x:Name="btn7" Foreground="#83D744" Click="btn7_Click" BorderBrush="#83D744" BorderThickness="0.5" Content="7" Width="80" RenderTransformOrigin="0.557,0.693" d:LayoutOverrides="HorizontalAlignment" Background="Black" Opacity="0.2" Margin="0,0,5,0" />
<Button FontSize="15" Foreground="Black" FontWeight="Bold" x:Name="btn8" Click="btn8_Click" Content="8" Width="80" Background="#FF50504F" Margin="0,0,5,0"/>
<Button FontSize="15" Foreground="Black" FontWeight="Bold" x:Name="btn9" Click="btn9_Click" Content="9" Width="80" d:LayoutOverrides="HorizontalAlignment" Background="#FF50504F"/>
</StackPanel>
So could anyone help me please how to solve this thing..
Thanks!
add transparency to a brush used for Background
hex code for Black color is #000000
change alpha channel to make it semi-transparent (Background="#50000000") and remove Opacity="0.2"
<Button x:Name="btn7"
FontSize="15" FontWeight="Bold" Foreground="#83D744"
Click="btn7_Click"
BorderBrush="#83D744" BorderThickness="0.5"
Content="7" Width="80" RenderTransformOrigin="0.557,0.693"
d:LayoutOverrides="HorizontalAlignment"
Background="#50000000" Margin="0,0,5,0" />
Make the opacity of the button 0.2 to 1
I have two groupboxes. GroupBox1 and GroupBox2. Is it possible to move controls inside GroupBox1 to GroupBox2 during runtime ?
For example in the following xaml file if I want to move the label1 in GroupBox1 to GroupBox2 during run time. How should I do it ?
<Grid>
<GroupBox Name="GroupBox1" HorizontalAlignment="Left" Height="400" VerticalAlignment="Top" Width="330" >
<StackPanel Orientation="Horizontal">
<Label Content="MyContent" x:Name="label1" FontSize="16"/>
<Image Name="ImageName1" VerticalAlignment="Bottom" Width="62" Height="42"/>
</StackPanel>
</Groupbox>
<GroupBox Name="GroupBox2" HorizontalAlignment="Left" Height="400" VerticalAlignment="Top" Width="330" >
<StackPanel Orientation="Horizontal">
<Label Content="MyContent" x:Name="label2" />
<Image Name="ImageName2" VerticalAlignment="Bottom" Width="62" Height="42"/>
</StackPanel>
</Groupbox>
</Grid>
Note :
I do know that I can transform the position of controls during run time by changing their margin value like this:
test.Margin = new Thickness(0, -5, 0, 0);
Just remove it from one StackPanel and put into another.
stackpanel1.Children.RemoveAt(stackpanel1.Children.IndexOf(label1));
stackpanel2.Children.Add(label1);
How can I draw a histogram on the Radslider like the image shown below using C# WPF? I've searched on net but not getting info.
Hi,
<StackPanel Grid.Column="1" Margin="7,-72,7.5,0">
<telerik:RadCartesianChart Palette="Summer" >
<telerik:RadCartesianChart.HorizontalAxis>
<telerik:CategoricalAxis Visibility="Hidden"/>
</telerik:RadCartesianChart.HorizontalAxis>
<telerik:RadCartesianChart.VerticalAxis>
<telerik:LinearAxis Visibility="Hidden" MajorStep="20" />
</telerik:RadCartesianChart.VerticalAxis>
<telerik:RadCartesianChart.Series>
<telerik:BarSeries ItemsSource="{Binding KeyValue, Mode=TwoWay}" CategoryBinding="Key" ValueBinding="Value">
<telerik:BarSeries.PointTemplates>
<DataTemplate>
<Rectangle Width="3" Fill="SkyBlue"/>
</DataTemplate>
</telerik:BarSeries.PointTemplates>
</telerik:BarSeries>
</telerik:RadCartesianChart.Series>
</telerik:RadCartesianChart>
</StackPanel>
<telerik:RadSlider Minimum="{Binding LowValue,Mode=TwoWay}" Height="13"
Margin="5" Grid.Column="1" Maximum="{Binding HighValue,Mode=TwoWay}"
SelectionEnd="{Binding SelectionHigh,Mode=TwoWay}"
SelectionStart=" {Binding SelectionLow,Mode=TwoWay}"
TickPlacement="TopLeft"
SelectionChanged="RadSlider_SelectionChanged" SelectionRangeEnabled="True"
IsDirectionReversed="False" SmallChange="10" VerticalAlignment="Bottom">
</telerik:RadSlider>
Instead of customizing RadSlider you can add a RadChart & RadSlider in the same column as I've shown.
I am just putting the Xaml code With the bindings, Now you can write the logic for histogram.
I was hoping someone could help me out here. I have 2 textboxes and a button within a dockpanel and I would like to get the 2 textboxes to stretch and shrink based on window size.
I have a dockpanel which contains a bunch of menu buttons on the left and within this dock I have another dock with 2 textboxs and a button. When I resize the main window, I would like the right dock to shrink the textboxes so that the right dock just doesn't dissapear when hit against the left dock. Does this make sense?
<DockPanel LastChildFill="False">
<Button DockPanel.Dock="Left" Margin="5, 0, 0, 0" Name="button1" Content="1" FontSize="10" Foreground="#FF565656" Width="64" Height="40"/>
<Button DockPanel.Dock="Left" Margin="5, 0, 0, 0" Name="button2" MinWidth="25" />
<DockPanel LastChildFill="False" DockPanel.Dock="Right" Margin="5, 0, 5, 0">
<TextBox DockPanel.Dock="Left" Name="textBoxUsername" Text="" TextWrapping="Wrap" ToolTip="Enter username" FontSize="11" FontWeight="Normal" Height="20" HorizontalAlignment="Left" Width="90" d:LayoutOverrides="GridBox" KeyUp="textBoxUsername_KeyUp" />
<PasswordBox Margin="5, 0, 0, 0" DockPanel.Dock="Left" Name="textBoxPassword" ToolTip="Enter password" Height="20" d:LayoutOverrides="HorizontalAlignment, GridBox" Width="90" KeyUp="textBoxPassword_KeyUp" />
<Button DockPanel.Dock="Left" Margin="5, 0, 0, 0" Name="buttonLogin" Content="Login" Height="20" MinWidth="70" Click="buttonLogin_Click" Width="500" />
</DockPanel>
</DockPanel>
This currently will just have the right dockpanel dissapear all together when the window is resized below the width of everything in the panel. I would like to have the right panel (the embedded dockpanel) shrink in size. Is this possible without a huge re-write effort? I obviously left a lot of the code out... Any help would be appreciated.
UPDATE
I am getting closer, but still not quite what I was hoping for. I added a grid, this allows the stretching, but I was hoping to leave everything stationary to the right. Meaning, I only want to shrink, not stretch but it be pinned to the right.
Here is the what it looks like now.
<DockPanel LastChildFill="False">
<Button DockPanel.Dock="Left" Margin="5, 0, 0, 0" Name="button1" Content="1" FontSize="10" Foreground="#FF565656" Width="64" Height="40"/>
<Button DockPanel.Dock="Left" Margin="5, 0, 0, 0" Name="button2" MinWidth="25" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MaxWidth="110" />
<ColumnDefinition Width="*" MaxWidth="110" />
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Name="textBoxUsername" Text="" TextWrapping="Wrap" ToolTip="Enter username" FontSize="11" FontWeight="Normal" FontStyle="Normal" Foreground="#FF9C9C9C" FontFamily="Arial Unicode MS" Height="20" d:LayoutOverrides="GridBox" KeyUp="textBoxUsername_KeyUp" Margin="5,13,5,0" MaxWidth="110" VerticalAlignment="Center" HorizontalAlignment="Stretch" />
<PasswordBox Grid.Column="1" Margin="5,13,5,0" Name="textBoxPassword" ToolTip="Enter password" Height="20" d:LayoutOverrides="HorizontalAlignment, GridBox" KeyUp="textBoxPassword_KeyUp" MaxWidth="110" VerticalContentAlignment="Center" />
<Button Grid.Column="2" DockPanel.Dock="Left" Margin="5,13,5,0" Name="buttonLogin" Content="Login" Template="{StaticResource ButtonControlTemplate2}" FontFamily="Arial" BorderBrush="{x:Null}" Background="{x:Null}" Height="20" MinWidth="70" Click="buttonLogin_Click" />
</Grid>
</DockPanel>
So this is centering everything within the the space it has. As soon as I put the horizontal alignment to "Right", the textboxes get crushed like this
Any thoughts on this?
This is happening because of the precedence of the textbox content. The TextBox's own width will be always equal to its content, so if you want some textboxes to have a different value, you should either set their Width property or set their parent's Width property.
You might me interested in a solution either this:
<TextBox Name="textBoxUsername" Width="100" ... />
Or this:
...
<ColumnDefinition Width="110" />
<ColumnDefinition Width="110" />
<ColumnDefinition Width="100" />
...
Or even this:
<TextBox Name="textBoxUsername" MinWidth="100" ... />
Note the MinWidth property.