|
Hi,
To get Rounded edge Listbox i searched for samples and finally get that.Here my code.
In XAML:
<ListBox Margin="22,122,27,126" Style ="{DynamicResource RoundedBox}" Name="listBox1" Background="DarkSeaGreen" Foreground="Yellow" SelectionChanged="listBox1_SelectionChanged" >
in ResourceDicationary WPF.XAML
<Style x:Key="RoundedBox" TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="BorderThickness" Value="3"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="0,0,1,1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border CornerRadius="5,5,5,5" BorderThickness="1,1,1,1" RenderTransformOrigin="0.5,0.5" x:Name="border" BorderBrush="#FFFFFFFF">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Border.RenderTransform>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Finally i got the rounded edge but..the background colr has gone and now it is transparent.
What im missing?Im new to WPF.Pls help me.
Before inclcuidn resourcedictionary in XAML,it shows the clor.After i inserted the line
Style ="{DynamicResource RoundedBox}" ..the colrs goes but i get rounded edge listbox.
|
|
|
|
|
Maybe set the Border's Background property...
<Border Background="{TemplateBinding Background}" CornerRadius="5,5,5,5" BorderThickness="1,1,1,1" RenderTransformOrigin="0.5,0.5" x:Name="border" BorderBrush="#FFFFFFFF">
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes i got that.after adding border background i get that colr.
I cannot get text display.
Im pressing button,then text display in listbox.But it didnot display.
private void button2_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("2nd Button form C#");
string str = "C#item";
listBox1.Items.Add(str);
}
|
|
|
|
|
shanmugarajaa wrote: Im pressing button,then text display in listbox.But it didnot display.
Your template doesn't provide an items host.
There's an example of a rounded listbox in the documentation
(scroll down to see the different samples):
ItemsControl.ItemsPanel Property[^]
There's also a complete sample template for listbox and many
other controls...
ListBox ControlTemplate Example[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am wondering if anyone can point me to some code (or DLL) to build a native OpenFileDialog and FolderBrowserDialog in wpf / xaml, rather than using the System.Windows.Forms controls?
We have now replaced the Forms MessageBox with a native WPF taskdialog, which looks much better and behaves more consistently. I would like to do the same for OpenFileDialog and FolderBrowserDialog.
Thanks,
Tim
|
|
|
|
|
WPF has a OpenFileDialog class in the Microsoft.Win32 namespace.
For Folder Browser dialog, see my blog[^]
I thought Pete O'Hanlon was working on a WPF version at one time
It's definitely a project to make a WPF version to replace the OS
dialogs...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have been working on one - it's something that I keep coming back to when I have some free time. It's a hell of a complex beast though, as I'm trying to make it completely skinnable.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I've only just been able to get back to this question - sorry for the long delay in responding. I guess it looks like this is a complex issue - I'll keep wrapping the System.Windows.Forms controls for the time being, and look out for further developments on this question. Hopefully Microsoft might build something into a future version...
Thanks,
Tim
|
|
|
|
|
I've got a 3rd party control:
class Foo : SomeWPFControl, INotifyPropertyChanged
{
public DateTime Start { get; }
public event PropertyChangedEventHandler PropertyChanged;
}
I slap this control on my view. Then I code up a little ViewModel. All is good.
I need to do work in my ViewModel when the control's Start property changes. How do you recommend doing this?
Attempt #1: I tried creating a DateTime property in my view model, then binding the control's .Start property to my property in the ViewModel, but that didn't work because "Start is a read-only property". Fail.
Attempt #2: I can listen to control.PropertyChanged inside my view, and when it fires, call some function on my ViewModel. But that doesn't seem very MVVMish. Fail?
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Have you tried, in the binding, specifying "Mode=OneWayToSource"?
If that doesn't work, then if I'm interpreting this correctly, #2 is probably the way to go.
|
|
|
|
|
Yeah, I still get a compiler error when specifying Mode = OneWayToSource.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Strange... Might not be set up properly as a DependencyProperty. #2 might be your only option, unfortunately.
|
|
|
|
|
There is a DependencyProperty on the class:
public Foo
{
public static DependencyProperty StartDateProperty;
public DateTime StartDate
{
get { ... }
}
}
The only way to change the StartDate is by clicking a button in the 3rd party control.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Hmm, strange way of setting it up...
I mean, you could bind another control to that value, but you can't bind the "StartDate" to a CLR object.
Yeah, I don't see a solution here other than hooking PropertyChanged.
|
|
|
|
|
Alright, well that's a legitimate answer, too. Thanks.
I'm mostly a newb when it comes to WPF, and definitely a newb when it comes to MVVM. I just wanted to be sure I wasn't doing things improperly. If this is the only way to make this work, alrighty.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Yeah, it's not ideal, but you do what you have to do, right?
|
|
|
|
|
Is the Start property in the control readonly? What is the mechanism for updating this property?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The Start property is a readonly .NET property:
public DateTime Start
{
get { ... }
}
There is a static DependencyProperty behind the scenes:
public class Foo
{
public static DependencyProperty StartProperty;
}
Pete O'Hanlon wrote: What is the mechanism for updating this property?
If the user clicks a button in the 3rd party control, the .Start will change.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
modified on Wednesday, December 9, 2009 5:38 PM
|
|
|
|
|
Hello,
Fairly new to WPF so hope this isn't going to be a case of failing to RTFM but I just can't see what has gone wrong.
I am modifying an existing user control to show slightly different data in a list depending on a setting on the control. I have registered the dependency property, added a get;set to use it else where in code and it comes up in the Intellisense in the XAML file. However it is not set to the value I've set it to in the XAML when it is check in the controls constructor.
Here is the relevant bits of the user control:
public partial class StationGroupControl : UserControl
{
public StationGroupControl()
{
try
{
if (ShowAggregates != true)
...
public static DependencyProperty ShowAggregatesProperty =
DependencyProperty.Register("ShowAggregates",
typeof(Boolean),
typeof(StationGroupControl),
new FrameworkPropertyMetadata(false));
public Boolean ShowAggregates
{
get
{
return (Boolean)GetValue(ShowAggregatesProperty);
}
set
{
SetValue(ShowAggregatesProperty, value);
}
}
And the XAML:
<ResearchCtrl:StationGroupControl Name="MultStation" HorizontalAlignment="Left" Margin="-122,0,0,0" Validation.Error="Ctrl_Error" ShowAggregates="True"></ResearchCtrl:StationGroupControl>
Frustratingly this seemed to be working and I then refactored the code down to smaller chunks and it inexplicably stoppped working. It has me doubting if it was ever working properly.
Is there some issue with using a boolean? Something else I need to do? Any way of debugging what is actually happening?
I'm pushed for time on this so any suggestion gratefully received.
Robert.
|
|
|
|
|
You're testing the value in the constructor, but it's not being set until AFTER.
The XAML is going to first create the object, THEN start setting properties... So basically what's happening is:
1) Object created
2) Constructor fires, checking ShowAggregates value
3) XAML parser sets the Name property
4) XAML parser sets the HorizontalAlignment property
...
7) XAML parser sets ShowAggregates to true
EDIT: Oh, should have added... The solution is to hook the Initialized event, or override OnInitialized, and do the check there.
|
|
|
|
|
Thanks, as suspected if I'd read the "manual" more closely I'd have spotted that eventually, if I wasn't mildly panicking I probably would have.
Thanks again Ian!
|
|
|
|
|
Hello again,
I tried moving the code to the Initialized event but it still wasn't set. I've now moved to the Loaded event and it is there so that's where I've left it for the moment. Let me know if you think this might cause a problem.
Thanks,
Robert.
|
|
|
|
|
|
Hi,
Is there a way in xaml/wpf to freeze first item in listbox from scrolling?
Thanks
|
|
|
|
|
Here is the scenario:
1. Open Visual Studio 2008, create new project...
2. Select WPF Custom Control Library as the project type
3 Open the Generic.xaml resource dictionary located in the Themes folder
4. Add a simple brush such as:
<SolidColorBrush x:Key="BackgroundBrush" Color="Yellow"/>
5. Change the Background property of the nested Borer Control from
Background="{TemplateBinding Background}"
to
Background="{DynamicResource BackgroundBrush}"
Now when you compile and use this control in any project, the background will NOT be yellow. BUT, if you change the background property to be a StaticResource as such
Background="{StaticResource BackgroundBrush}"
...it will work. Why is this? Why does StaticResource work but not DynamicResource???
|
|
|
|