|
About
I created this range slider[^] control. It has 2 thumbs, thus allowing for a range,
Functionality
a) Clicking the track bar OUTSIDE the thumbs should center the thumbs on that point.
b) Dragging INSIDE the thumbs should move both thumbs equally.
Issues
When the window isn't too big, it all works OK. But, resize the window really wide and then try A & B above. It doesn't move right.
The code you need to see is in the RangeSlider control, in the Border_MouseDown and Border_MouseMove events.
I would appreciate any help or suggestions you can offer.
If it's not broken, fix it until it is
|
|
|
|
|
I have created a dual thumb slider as shown here[^].
I also added in some mouse events, and I'm close to done.
Now, I'd like to style it like this[^].
But it seems that the control template is preventing the style from showing.
How do I use this style and control together?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
I need to set a ListBox's Items heights so that they fill the entire listbox:
In this window[^], everything below the splitter is my control. On the left is the listbox.
You can see there's open space below the last list item. It's ever more evident here[^]
Here's my XAML:
<ListBox Grid.Column="0"
x:Name="categoryList"
BorderBrush="LightGray"
BorderThickness="0,0,1,0"
ItemsSource="{Binding Categories}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
IsEnabled="False"
Background="White"
Width="100"
Margin="0,-2,0,0">
<pre>
<ListBox.Style>
<Style TargetType="{x:Type ListBox}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</ListBox.Style>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Height" Value="{Binding Path=DataContext.ListItemHeight, RelativeSource={RelativeSource AncestorType=Grid}}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="LightGray"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="SteelBlue"/>
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding CategoryName}"
VerticalAlignment="Center"
FontSize="16"
Margin="10,0,0,0"/>
</DataTemplate>
</ListBox.ItemTemplate>
and the control's SizeChanged event:
private void sizeChanged(object sender, SizeChangedEventArgs e)
{
ListItemHeight = Math.Floor(this.ActualHeight / (Categories.Count + 1));
}
What am I doing wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Sounds like you need to use a UniformGrid[^] as your ItemsPanel[^]:
<ListBox
Grid.Column="0"
x:Name="categoryList"
BorderBrush="LightGray"
BorderThickness="0,0,1,0"
ItemsSource="{Binding Categories}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
IsEnabled="False"
Background="White"
Width="100"
Margin="0,-2,0,0"
>
<ListBox.Style>
<Style TargetType="{x:Type ListBox}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</ListBox.Style>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="LightGray"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="SteelBlue"/>
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock
Text="{Binding CategoryName}"
VerticalAlignment="Center"
FontSize="16"
Margin="10,0,0,0"
/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="1" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That did it!!
You are a god!
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Using VS2013 on Win7:
I'm developing several WPF desktop apps at work (on a DoD network). Up until yesterday, everything was fine. This morning, when I tried to compile for the first time, I got this error for all of the XAML files in the solution:
Unknown build error, 'This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.'
This happens even in freshly created solutions with absolutely nothing added to the template-provided code.
It does not happen in MVC, WinForms, or ASP.Net applications.
Does anyone have any clues? FWIW, any solution provided must NOT require admin rights, since I don't have/can't get those privileges on a DoD system. This means I can't change config files that live on the C drive, or edit the registry.
I've already tried specifying the following in the assemblyinfo.cs file:
using System.Configuration.Assemblies;
[assembly: AssemblyAlgorithmId(AssemblyHashAlgorithm.SHA512)]
I tried all of the possible values for the indicated enumerator with no change in behavior.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
It looks like changing config files or the registry is the only available workaround:
After the above modification devenv config would look like:
<configuration>
...
<runtime>
...
<enforceFIPSPolicy enabled="false"/>
</runtime>
</configuration>
According to this SO post[^], Visual Studio is using MD5 for "coordinating source files for debugging".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well, the security Nazis here won't allow that to be changed. I thought specifying the attribute in assemblyinfo.cs would be sufficient, but it wasn't.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
First: I am an absolute beginner and I want to learn basics.
I have created a Silverlight-App and embedded it in a asp.net MVC page on a WebServer (it works fine). Now I want to do my first steps: Loading an Xml-File from the WebServer into my SilverlightApp, which running in the Browser of a ClientComputer
Question:
How can I send some "basic kind of request" from the SilverlightApp to the Server to send the xml-file?
I surfed a lot in the internet, but I am confused about all of these very complex data-access-possibilities.
|
|
|
|
|
You do realise that Silverlight has a sunset date of 2020 and won't be supported in the newer browsers!
Do some research into WCF although you should be getting your data from the MVC component. Weird setup, I've never heard of this structure being used!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
For 15 years I was a FoxPro/Visual FoxPro developer before moving into C# and now WPF.
Back in my Fox days I created my own framework. I took all the years of experience I had in developing Fox solutions and created a set of controls, forms, generic procedures, etc, and combined them into a reusable set. Then when I created a new project I ran a tool which build my new solution from my "framework".
Now that I've been at C# for 10 years, and WPF for 5, I've often thought of doing the same. Each time I start a new project I have to create a solution from scratch. I generally create or include the one or more of the following projects in a solution:
1) DAL - Data Layer
2) BL - Business Layer
3) Entities - DTO's
4) App Core - The 'engine' of the app.
5) App Shared - Contains enums, event args, and other stuff used across all projects in the app
6) Generic Utils - Logger class, Extensions, other generic code used in any .Net app
7) WPF/SL/Phone/Tablet UI
8) WPF Utils - Stuff specific to WPF/SL/Win Phone apps such as RelayCommand, BindableBase class, etc
9) WPF controls library
10) App specific control libraries
Most of this is in any given WPF solution I create.
So I've realized that back in my Fox days I could easily get a new project set up with a few mouse clicks. Now in C#/WPF I spend a half day or so creating all of the above. Then more time tweaking as I get going.
So assuming I did this...some of the projects in the solution would reside in a common area and just be included in the solution, such as WPF Utils or WPF Controls, while some would be generated by the tool.
1) Any reason NOT to do create my own framework again?
2) Any suggestions?
3) Any components not listed above that you would add?
I welcome your thoughts.
If it's not broken, fix it until it is
|
|
|
|
|
Same boat, approx 2 hours to set up a new project. However I have all the common stuff in existing projects and just include them in every project.
The WCF (we HAVE to use a service into the database) is the easiest as I have a code generator for that, the UI is just a copy paste from the last project.
As I do a new project every 3-6 months this stuff is evolving all the time and I can't pause to build a "framework". Actually it is a setup template in VS and they are a bitch to build, I did one for Silverlight.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I played with styles for buttons. I created a rounded button with a radial gradient brush. When it gets focus, a black thick border becomes visible, when the mouse hovers over the button, it receives a transparent border thus "shrinking" the button:
<Style x:Key="RoundedButton" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Background" Value="{StaticResource GreenGradientBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}" RadiusX="8" RadiusY="8" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Button.IsFocused" Value="true">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}" Stroke="Black" StrokeThickness="4" RadiusX="8" RadiusY="8" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Button.IsMouseOver" Value="true">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}" Stroke="Transparent" StrokeThickness="3" RadiusX="8" RadiusY="8" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Button.IsEnabled" Value="false">
<Setter Property="Background" Value="{StaticResource GrayGradientBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
It works. But look at the code. True, it is nicely formatted and hence looks good
It has a smell. So much copy-paste .
I can do better, can't I? What about a TemplateBinding of Stroke and StrokeThickness to BorderBrush and BorderThickness ?
<Style x:Key="RoundedButton" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Background" Value="{StaticResource GreenGradientBrush}"/>
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}" RadiusX="8" RadiusY="8" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Button.IsFocused" Value="true">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="10" />
</Trigger>
<Trigger Property="Button.IsMouseOver" Value="true">
<Setter Property="BorderBrush" Value="Yellow"/>
<Setter Property="BorderThickness" Value="10" />
</Trigger>
<Trigger Property="Button.IsEnabled" Value="false">
<Setter Property="Background" Value="{StaticResource GrayGradientBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
But it does not work: hardly a reaction is visble with the mouse over the button or on a focussed button. I set the thickness to 10 pixels already, doesn't help.
Why is it necessary to replace the whole Template in the Trigger s?
|
|
|
|
|
StackOverflow has the answer:
BorderThickness is not that easy, it is a struct of type Thickness (and can be composite, like BorderThickness=".0,.0,2,2" ), while StrokeThickness property is of type double .
You need IValueConverter to make this binding work.
One alternative to an IValueConverter , suggested in the same thread[^], is to bind the StrokeThickness to one part of the BorderThickness :
<Rectangle
Fill="{TemplateBinding Background}"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness.Top}"
RadiusX="8" RadiusY="8"
/>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, it works.
And now I understand the reason behind it: with the failed conversion, StrokeThickness stayed 0 , and consequently a border - regardless of its color - could not be shown. And that's also the reason why no border was shown in the non-focussed, non-mouse-over button either when I tried that...
|
|
|
|
|
I've done this more times than can count... for some reason this time I'm hung up.
My XAML:
<Window x:Class="Blah.MyApp.UI.Desktop.MainWindow.MainWindowView"
x:Name="mainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mw="clr-namespace:DFT.Falcon6.UI.Desktop.MainWindow"
xmlns:t="clr-namespace:DFT.Falcon6.UI.Desktop.Controls.Timeline"
xmlns:conn="clr-namespace:DFT.Falcon6.UI.Desktop.Controls.Connection"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Title="{Binding WindowTitle}"
WindowStartupLocation="CenterScreen"
Height="600"
Width="800">
<pre>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<i:InvokeCommandAction Command="{Binding CloseWindowCommand}" />
</i:EventTrigger>
In the "Command=" part - it won't compile... Says
The property 'Command' was not found in type 'InvokeCommandAction'
I don't get it.. what am I missing here?????????
If it's not broken, fix it until it is
modified 2-Jun-15 19:34pm.
|
|
|
|
|
The code looks OK. I assume you've referenced the System.Windows.Interactivity assembly?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm working on an WinForms replacement app in WPF 4.5.
The current WinForms app streams video from a C++ component. The C# WinForms control has this code:
public void StartVideoStream(int iCamera)
{
if (InvokeRequired)
{
delStartVideoStream del = new delStartVideoStream(StartVideoStream);
Invoke(del, new object[] { iCamera });
}
else
{
if (!VideoPlaying)
{
int iSuccess = ClientComm.StartVideoStream(iCamera, ucVideoPlayer.Handle,
(ClientComm.streaming_protocols)Properties.Settings.Default.VideoStreamProtocol,
Properties.Settings.Default.VideoStreamFrameRate);
if (iSuccess != 0)
{
Debug.WriteLine("[ucVideo] Could not play video.");
}
}
else
{
ClientComm.SelectVideoStream(iCamera);
}
VideoPlaying = true;
}
}
You can see that it passes its handle to the COM component which writes the video directly to it.
The problem is that in WPF controls do not have handles. How can I do this I WPF?
Thank you.
If it's not broken, fix it until it is
|
|
|
|
|
What you need to do is implement the IWin32Window interface on your WPF Window so it looks something like this:
public class MainWindow : Window, IWin32Window
{
public IntPtr Handle
{
get
{
return new WindowInteropHelper(this).Handle;
}
}
} Now, you can get this handle from any user control by casting the main window to IWin32Window.
|
|
|
|
|
Hi Pete,
I'm not sure I totally understand.
In the snippet you provided, that allows me to get the handle of the MainWindow, but I don't see how I would the handle of a control that the video can be displayed in.
Could you elaborate a bit more please?
Thank you
If it's not broken, fix it until it is
|
|
|
|
|
Basically, you need a handle to the window that you are going to display your content in. There is no such thing as a handle at the level of a user control, it applies to the window that displays it. That's all you need - the Handle to the containing window.
|
|
|
|
|
That's not going to work then. I have other content to be displayed along side the 2 videos. using the window handle would cause the video to consume the entire window.
I'm looking at WPFMediaKit on CodePlex. Looks promising.
If it's not broken, fix it until it is
|
|
|
|
|
I want to change the fontsize of the Window.Title,
But I found < Window FontSize = "14" > not worked for the Title,
just for the content of window.
|
|
|
|
|
You need to customise the window's "chrome". If you're using .NET 4.5, the classes to do this are built-in[^]. For earlier versions, there's a library[^] you can use, although the site seems to be down at the moment.
There's even a demonstration of how to use it here on CodeProject:
WPF Custom Chrome Library[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
<Window.Resources>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="FontSize" Value="20"/>
</Style>
<Style TargetType="{x:Type Button}" x:Key="ButtonStyle">
<Setter Property="Height" Value="36"/>
<Setter Property="Width" Value="60"/>
</Style>
</Window.Resources>
<Grid>
<Button Content="Button" Style="{StaticResource ButtonStyle}"/>
<Button Content="Button" Style="{StaticResource ButtonStyle}" Margin="156,144,286,145" />
<TextBlock HorizontalAlignment="Left" Margin="108,38,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="154" Height="40"/>
</Grid>
I am a rookie in WPF, I am wonder why the Button need :
Style="{StaticResource ButtonStyle}" , a explicit Style syntax.
But the TextBlock don't need it.
Thanks
|
|
|
|
|