|
I was typing my reply when you sent yours. My apologies.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
No big deal, I just had one of those bonehead moments when I realize it must be time to go home.
Brent
|
|
|
|
|
You don't have a width specified so the Grid will shrink to be as small as possible, i.e. just wide enough to hold your controls. And it will pin itself into the bottom left corner. Your right/top margins will only be used if the controls are big enough to fill the width/height of your window.
Change HorizontalAlignment="Left" to HorizontalAlignment="Stretch" (or delete the assignment all together, stretch is the default). The grid will take up as much room as possible leaving the margins specified on each side.
Depending on how you want your controls contained to look, you might want to put a StackPanel in the Grid to hold the controls or switch the Grid to a DockPanel and dock your controls to the bottom.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
I have a settings page that I want to hide certain settings unless it has been unlocked by a password by someone authorized to make the changes.
Right now what I have:
Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Unlocked, Converter={StaticResource ResourceKey=BooleanVisibility}}"
Which works fine. However, it seems extremely time consuming to type that in for every control, even doing copy and paste.
I tried:
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BooleanVisibility" />
<Binding x:Key="LockedProperty" RelativeSource="{RelativeSource AncestorType={x:Type Window}}" Path="Unlocked" Converter="{StaticResource ResourceKey=BooleanVisibility}" />
</UserControl.Resources></pre
And the Visibility of the control set to:
<pre>Visibility="{StaticResource ResourceKey=LockedProperty}"
Which complains that "A 'Binding' cannot be set on the 'Value' property of type 'DictionaryEntry'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject." Which makes sense now that I'm reading it again. It thinks I'm trying to bind UserControl.Resources.
Is there any way to make a binding template or resource that would let me make the binding call a lot simpler?
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
See RelativeSource actually tries to find the window element just by traversing through the entire visual tree. So I recommend to use ElementName rather than an Ancestor.
Use x:Name for the Window and use
Visibility = {Binding ElementName=win, Path=Unlocked, Converter={StaticResource BooleanVisibility}}
Actually this will make the binding to avoid traversing through the Visual Tree.
Abhishek Sur
Don't forget to click "Good Answer" if you like this Solution. Visit My Website-->www.abhisheksur.com
|
|
|
|
|
I am tring to bind a xaml element property to a property defined in the class.
I've tried the following:
public class FMChartMS
{
private double setting = 275;
public double MyProperty { get { return setting; } }
}
<my:FMChartMS x:Name="ChartPage">
<Grid Height="{Binding MyProperty, ElementName=ChartPage}" />
It crashes the app. What am I missing?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
You need to make a DependencyProperty for MyProperty.
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(double), typeof(FMChartMS), new PropertyMetadata(false));
public double MyProperty
{
get { return (double)this.GetValue(MyPropertyProperty); }
set { this.SetValue(MyProperty Property, value); }
}
I'm using the standard notation for naming dependency properties, PropertyNameProperty. That's why it's called MyPropertyProperty when using your example. In my project I have a property called Unlock with the dependency property called UnlockProperty. I like to declare the DependencyProperty first so IntelliSense will help fill in the blanks.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
That didn't work.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Sorry, there was a copy/paste error.
DependencyProperty.Register("MyProperty", typeof(double), typeof(FMChartMS), new PropertyMetadata(false));
should be
DependencyProperty.Register("MyProperty", typeof(double), typeof(FMChartMS), new PropertyMetadata(0d));
The "0d" is the initial value of the property. You can set it to whatever you want.
Warning: The "d" is very important. For some reason the PropertyMetadata constructor does not implicitly convert values passed into, so even though you can use double var = 0; in code, new PropertyMetadata(0) will cause your program to fail just the same as it is now with being passed a boolean. It has to be passed a value of the same type being declared.
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
How do we change theme for a silverlight application at run-time. Suppose I have "Theme1.xaml", "Theme2.xaml" and "Theme3.xaml" as themes inside 'Themes' folder, and I wish to apply them on button-click or combobox-selection.
In WPF, I used to get the required result with following code -
ResourceDictionary skin = new ResourceDictionary();
skin.Source = new Uri(@"Themes/" + themeName + ".xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(skin);
But for Silverlight, I'm not sure how to do it. Any idea? Please do not provide link with 'Telerik' content. I have seen it already.
|
|
|
|
|
Hi Experts,
I am unable to locate a property similar to WindowsForm "DropDownWidth" Property for the Combo Box in WPF. Is there a work around to achieve this functionality?
Please help!
Thanks in advance.
Regards,
Samar
P.S.: Just FYI for those who are not aware, "DropDownWidth" Property changes the width of the drop down area. The area when the Combo Box is clicked to show its master contents.
modified on Friday, July 30, 2010 2:40 AM
|
|
|
|
|
Dear friends,
I am new to WPF and I have to design pages, and I do not know how to design pages that fits for many screen size
Is it possible to design screen that fits in all the screen size? Then how?
If not all the screen size I need to fix it for 4/3 screen resolution like
800 600
1024 768
1280 960
1600 1200
1792 1344
Any idea? Link?
Thanks
|
|
|
|
|
The layout system in UI is designed to be resolution independent. Rather than positioning things absolutely, you can lay things out in any one of a number of panels (such as a Grid), and use margins and padding to achieve whatever effects you want.
"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
|
|
|
|
|
Thanks for reply,
My problem like these ..
i have button and i specified size for the button in One screen size... when i change to other screen size ..the button size same
i tried to by removing button size and just to specify the margin ...if i set margin the (then the margin space remains same)
i do not know what to do?
thanks
|
|
|
|
|
I have a list of data item objects (ObservableCollection<MyDataItem> ) bound to a line series, and I need to change the symbol's visibility based on the value of a boolean property (ShowSymbol )in a given data item object. In other words, for a given LineSeries, each datapoint could potentially be represented by a different/unique symbol.
I've written a converter (VisConverter ) that is supposed to set the visibility of the symbol based on the value of the ShowSymbol property, and I've added the converter to the UserControl.Resources, but I'm not sure how I specify the property in the xaml.
Can anyone help?
SOLUTION ===================
Visibility="{Binding ShowSymbol, Converter={StaticResource VisConverter}}"
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
modified on Wednesday, July 28, 2010 3:54 PM
|
|
|
|
|
I have a collection of classes together that are formed together like tree. The whole collection is bound to a TreeView. One of the classes has a bool property called IsChanged:
public class ReportColumn
{
public string ColumnName { get; set; }
public object OriginalValue { get; set; }
public object ChangedValue { get; set; }
public bool IsChanged { get; set; }
}
In my XAML I created a DataTemplate for it:
<DataTemplate DataType="{x:Type local:ReportColumn}">
<StackPanel Orientation="Horizontal">
<!-- Column Name -->
<TextBlock Margin="0,0,5,0"
FontWeight="Bold">Name:</TextBlock>
<TextBlock Text="{Binding Path=ColumnName}"></TextBlock>
<!-- Original Value -->
<TextBlock Margin="20,0,5,0"
FontWeight="Bold">Original:</TextBlock>
<TextBlock Text="{Binding Path=OriginalValue}"></TextBlock>
<!-- Changed Value -->
<TextBlock Margin="20,0,5,0"
FontWeight="Bold">Change:</TextBlock>
<TextBlock Text="{Binding Path=ChangedValue}"></TextBlock>
</StackPanel>
</DataTemplate>
Then the whole thing is bound to the treeview. What I'd like is to make this node's foreground red when IsChanged is true. Can someone explain how to do this?
Everything makes sense in someone's mind
|
|
|
|
|
I'm almost bald from pulling my hair out over this bug.
I have a WPF window which as a section defined as follows:
<StackPanel Name="stackPaneln" Orientation="Horizontal" Margin="-1,29,0,54">
<DockPanel Name="navigation" >
<StackPanel Name="stackPanel1" Width="162" HorizontalAlignment="Left" Height="486">
<Button Height="103" Name="configurationViewerRequest" Width="120" Margin="0,5" Click="configurationViewerRequest_Click">
<StackPanel Orientation="Vertical">
<Image Source="Configuration_icon_by_obsilion.png" Height="73" />
<TextBlock Text="Configuration" TextAlignment="Center" Margin="0,5,0,0" />
</StackPanel>
</Button>
<Button Height="100" Name="systemStatus" Width="120" Margin="0,5" Click="systemStatus_Click">
<StackPanel Orientation="Vertical">
<Image Source="SystemMonitor.png" Height="73" />
<TextBlock Text="System Status" TextAlignment="Center" Margin="0,5,0,0" />
</StackPanel>
</Button>
<Button Height="103" Name="systemMonitor" Width="120" Margin="0,5" Click="systemMonitor_Click">
<StackPanel Orientation="Vertical">
<Image Source="ViewInfo.png" Height="73" />
<TextBlock Text="System Monitor" TextAlignment="Center" Margin="0,5,0,0" />
</StackPanel>
</Button>
</StackPanel>
</DockPanel>
<DockPanel Name="destination" Margin="10,0,0,0" Width="608">
</DockPanel>
</StackPanel>
The problem:
When one of the buttons in the Navigation panel is clicked, the user control that provides the functionality is loaded into the 'destination' dock panel. So I have a user control which has a treeview and an editor window. In the editor window I put a label with content = '<----the navigation of over there'
When the configuration button is clicked I create an instance of the editor, and do destination.Children.Add(controlEditor);
Problem: the control is shifted all the way to the right of the window (aligned with x=0 of the Window!!! instead of the DockPanel!!!!
Here is the xaml of the control I'm loading in case I screwed up there....
<UserControl x:Class="SnmpBrowser.ConfigurationManager"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" xmlns:ig="http://schemas.infragistics.com/xaml" d:DesignHeight="612" d:DesignWidth="800">
<Grid>
<DockPanel VerticalAlignment="Top" Height="536" Margin="12,12,640,64" >
<TreeView >
<TreeView.ContextMenu x:Uid="addItemContext">
<ContextMenu Name="context" Opened= "context_Opened" >
<MenuItem Name="header" Header="populated programmatically" >
<MenuItem Name="newItem" Header="Add New " Click="newItem_Click" />
<MenuItem Name="edit" Header="Edit....">
</MenuItem>
</MenuItem>
</ContextMenu>
</TreeView.ContextMenu>
<TreeViewItem Header="Agent" MouseRightButtonDown="ContextMenuHandler" Uid="agent" MouseEnter="SetSelected" />
<TreeViewItem Header="Devices" MouseRightButtonDown="ContextMenuHandler" Uid="device" MouseEnter="SetSelected" />
<TreeViewItem Header="Mother" IsSelected="True" MouseRightButtonDown="ContextMenuHandler" Uid="mother" MouseEnter="SetSelected"></TreeViewItem>
<TreeViewItem Header="System" MouseRightButtonDown="ContextMenuHandler" Uid="system" MouseEnter="SetSelected" />
</TreeView>
</DockPanel>
<DockPanel Margin="0,12,12,0" Name="destination" VerticalAlignment="Top" Height="536" HorizontalAlignment="Right" Width="622">
<Label Content="<-------- the menu is over there!" Height="28" Name="label1" />
</DockPanel>
<ListBox Height="Auto" HorizontalAlignment="Stretch" Margin="12,552,0,0" Name="messages" VerticalAlignment="Stretch" Width="Auto" />
</Grid>
</UserControl>
|
|
|
|
|
After doing a few more tests it turns out that the work area was 600x400 but the user control was 600x800.
After resizing the user control to the area of the dock panel, everything displays properly.
|
|
|
|
|
Hey All,
Hope we're well. I'm just trying to bind the IsEnabled property of a button to an IsValid property on my IWizardPage. Can I work it out?
The IWizardPage is implemented on a UserControl that is hosted in a ContentControl on the same control as the button. I've tried various thing including AncestorType things ... I'm trying this at the moment with no luck:
IsEnabled="{Binding ElementName=WizardHost, Path=Content.IsValid, Converter={StaticResource textBoolConverter}}"
The converter is there just for a breakpoint opportunity at the moment ...
|
|
|
|
|
Try something like this..
IsEnabled="{Binding Content.IsValid, ElementName=WizardHost, Converter={StaticResource textBoolConverter}}"
|
|
|
|
|
I rather suspect that you don't need a converter in there mate - both of them should be boolean values.
"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 have 4 images of same object.
I want to write small WPF application that show that object in 3D - using the those images.
How can i do it ?
I don't find any example that teach how to do it
Thanks for any help
|
|
|
|
|
See here. Maybe this[^] can help.
|
|
|
|
|
Hi, guys!
I'm having a bit of a trouble with my columns' headers in WPF Datagrid. Some of them are too long, and horizontal stratching is not an option: there are too many of columns, and user will not be able to see full text in headers.
Here is what I'd like to do
I want header "Word1 word2 word3 word4 word5 word6"
to look like
"Word1 word2 word3
word4 word5 word6" - so it srteches vertically.
Thanks in advance
|
|
|
|
|
I haven't tried it, but I should imagine that all you need to do is set a style with a TargetType of tk:DataGridColumnHeader , and set the TextWrapping in there.
"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
|
|
|
|