|
I know you don't use winforms but the question goes against all the design principles of WPF. I'd be interested in the reasons for not wanting to use xaml.
I have found one and that is building a grid based on a pivot but there you don't know the number of columns.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm using a multilevel grid and I need to change the appearance of the grid on the fly based on a user selection. I probably could use WPF in some fashion, as I use it for other controls. But, on the fly would be better for my application. I'm under the impression that anything done in WPF can be done in straight C#.
|
|
|
|
|
Sutton Mehaffey wrote: I'm under the impression that anything done in WPF can be done in straight C#.
While that is not 100% correct, there are some thing you probably can't do in code behind, it is 100% WRONG, WPF/Silverlight is ALL about the binding, until you embrace that you are going to struggle.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I got it working with Binding. Thanks. However, I have an unresolved issue concerning the binding.
I have a global array of zone descriptions[64]. Upon entering a window, the array is copied to a temp array of descriptions. The array is bound to to a List, which includes a zone number and the zone description (called zdentry - the description is named ZoneDesc). The user can edit the description, and I want to copy the change back into the temp description variable. But, I can't figure out where the change variable is. No form of zdentry or ZoneDesc is valid and creates errors. And, it won't let me 'set' anything in the ZoneDescEntry class either.
Any ideas? Thanks.
void CreateZoneDescTable()
{
List<ZoneDescEntry> zdentry = new List<ZoneDescEntry>();
for (byte i = 0; i < 5; i++)
{
zdentry.Add(new ZoneDescEntry()
{
ZoneNum = "Zone " + (i+1),
ZoneDesc = zonedescrip[i]
});
}
if (GlobalVars.system_type == 'D')
{
for (byte i = 5; i < 64; i++)
{
zdentry.Add(new ZoneDescEntry()
{
ZoneNum = "Zone " + (i+1),
ZoneDesc = zonedescrip[i]
});
}
}
ZoneDescTable.ItemsSource = zdentry;
}
public class ZoneDescEntry
{
public string ZoneNum { get; set; }
public string ZoneDesc { get; set; }
}
}
|
|
|
|
|
Not sure how you are set up but you are not implementing OnPropertyChange on your model public class ZoneDescEntry and your collections are generic rather than ObservableCollection this indicates that there is no notification about any changes to your data.
I use a BaseModel class that implements INotifyPropertyChanged and the Model implements IEditableObject this give me control of the editing process and I get notification of the data changes.
My BaseModel
public abstract class BaseModel : INotifyPropertyChanged
{
public BaseModel() { }
#region Events
/// <summary>
/// PropertyChanged event.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
#endregion
private bool _IsDataChanged;
public bool IsDataChanged
{
get
{ return _IsDataChanged; }
set
{
if (_IsDataChanged == value)
{
return;
}
var oldValue = _IsDataChanged;
_IsDataChanged = value;
OnPropertyChanged("IsDataChanged");
}
}
public void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
if (propertyName != "IsDataChanged")
{ IsDataChanged = true; }
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
/// <summary>
/// get a shallow copy of object of type T.
/// objects with other object properties has not been tested.
/// </summary>
public static T ShallowCopy<T>(object objToCopy) where T : class, new()
{
if (objToCopy == null)
{ return null; }
Type objType = typeof(T);
object oValue;
PropertyInfo oPropNew;
T objNew = Activator.CreateInstance<T>(); //hence the new() contsraint
//Debug.WriteLine(objType.Name + " = new " + objType.Name + "();");
PropertyInfo[] oPInfos = objType.GetProperties();
foreach (PropertyInfo oPInfo in oPInfos)
{
//may error if no mat
oPropNew = objType.GetProperty(oPInfo.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
oValue = oPInfo.GetValue(objToCopy, null);
oPropNew.SetValue(objNew, oValue, null);
}
return objNew;
}
public static T ReverseCopy<T>(object EditableObject, object SelectedObject) where T : class, new()
{
if (EditableObject == null)
{ return null; }
Type objType = typeof(T);
object oValue;
//Debug.WriteLine(objType.Name + " = new " + objType.Name + "();");
PropertyInfo[] oPInfos = objType.GetProperties();
foreach (PropertyInfo oPInfo in oPInfos)
{
//may error if no match
PropertyInfo oPropNew = objType.GetProperty(oPInfo.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
oValue = oPInfo.GetValue(EditableObject, null);
oPropNew.SetValue(SelectedObject, oValue, null);
}
return (T)SelectedObject;
}
}
The Model class
public class ZoneDescEntryDB : BaseModel, IEditableObject
{
private string _ZoneNum;
public string ZoneNum
{
get
{ return _ZoneNum; }
set
{
if (_ZoneNum == value)
{
return;
}
var oldValue = _ZoneNum;
_ZoneNum = value;
base.OnPropertyChanged("ZoneNum");
}
}
private string _ZoneDesc;
public string ZoneDesc
{
get
{ return _ZoneDesc; }
set
{
if (_ZoneDesc == value)
{
return;
}
var oldValue = _ZoneDesc;
_ZoneDesc = value;
base.OnPropertyChanged("ZoneDesc");
}
}
#region Edit methods
private ZoneDescEntryDB Backup { get; set; }
public void BeginEdit()
{
Backup = ShallowCopy<ZoneDescEntryDB>(this);
IsDataChanged = false;
}
public void EndEdit()
{
Backup = null;
IsDataChanged = false;
}
public void CancelEdit()
{
ReverseCopy<ZoneDescEntryDB>(Backup, this); Backup = null;
IsDataChanged = false;
}
#endregion Edit methods
}
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks. I'm going to try to implement your code in some fashion. I had tried the INotifyPropertyChanged, but couldn't get it to work, because I couldn't figure out where the new value was and how to store that new value in my zonedescrip[zonenum] array.
My code should be a little simpler. The Zone number never changes (a zone is a zone). The description is the only thing that can change. And, when it does, it goes back into a zonedescrip[zonenum] array. When the user clicks on a SAVE button, the zonedescrip array gets saved into a permanent place.
I need to figure out how your Edit calls work. Maybe I don't even need a temporary zonedecrip array. Just use the permanent array as the Source and copy back to the permanent array when the user clicks on SAVE. During what part of the user editing process do the BeginEdit, EndEdit, and CancelEdit methods get called?
|
|
|
|
|
You can always fetch the ListBox control using VisualTreeHelper and then set its items to Labels intead of TextBoxes .
|
|
|
|
|
I am developing a SL4 app by applying PRISM and MVVM pattern. I'd want to make users authenticate with username and password credentials before loading the shell (a common scenario), I want to show the login page, but after bootstrapper starts, because I want to use my Authentication Service, thats registered with container, and if user authenticates then to show the shell.
|
|
|
|
|
|
Is it possible to add a small button in a cell in WPF C1Flexgrid? Requirement is like that, button will be small with [...] will be at the right end and while clicking on that a small popup window will come. User can enter text on it and while closing that popup the text will come in grid cell.Kindly help me out.
Greeshma
|
|
|
|
|
It's a bit of a pain to do - look at flexgrid's CellFactory
|
|
|
|
|
Hi RugbyLeague,
Thank You for your reply.... I will try out the way you suggested and will let you know if it solves my problem.
|
|
|
|
|
Hi,
I am struggling with uploading images to server. It is working in local version. while hosting the images are not getting uploaded to server. can any body help me. its very very urgent.
If it is not possible pls suggest me how to read and write to sql server database. I tried with that too and failed.
Thanks in advance
|
|
|
|
|
The XAML's a bit long here, so please bear with me.
I have styled an expander to look like this[^].
I am very new to styling, so I could use some help. When the expander is collaped I want the rectangle and arrow to be gray. When expanded, I'd like to change the color to orange. I would also like to redraw the arrows facing up.
I got the idea from the expanders here[^].
I really don't know how to go about doing this. Could someone point me in the right direction?
The XAML is
<Window.Resources>
<Color x:Key="Color1">Gray</Color>
<Color x:Key="Color2">SlateGray</Color>
<Color x:Key="Color3">DarkSlateGray</Color>
<Color x:Key="HeaderGradientBrush1">DarkGray</Color>
<Color x:Key="HeaderGradientBrush2">White</Color>
<SolidColorBrush x:Key="ToggleButtonEllipseBorderBrush" Color="{StaticResource Color1}" />
<SolidColorBrush x:Key="ToggleButtonArrowBrush" Color="{StaticResource Color2}" />
<SolidColorBrush x:Key="ToggleButtonRectangleBrush" Color="{StaticResource Color2}" />
<SolidColorBrush x:Key="ToggleButtonBackgroundBrush" Color="Transparent" />
<SolidColorBrush x:Key="ContentAreaBackgroundBrush" Color="Transparent" />
<SolidColorBrush x:Key="ExpanderBorderBrush" Color="{StaticResource Color1}" />
<SolidColorBrush x:Key="ExpanderHeaderTextColor" Color="{StaticResource Color3}" />
<LinearGradientBrush x:Key="headerGradientBrush"
EndPoint="0.504,1.5"
StartPoint="0.504,0.03">
<GradientStop Color="{StaticResource HeaderGradientBrush1}" Offset="0" />
<GradientStop Color="{StaticResource HeaderGradientBrush2}" Offset="0.567" />
</LinearGradientBrush>
<!--Control template for the Toggle Button-->
<ControlTemplate x:Key="ExpanderToggleButton"
TargetType="{x:Type ToggleButton}">
<Grid Width="16"
Height="16">
<Path Stroke="{StaticResource ToggleButtonArrowBrush}"
Data="M 3,4 l 5,5 5,-5" />
<Path Stroke="{StaticResource ToggleButtonArrowBrush}"
Data="M 3,7 l 5,5 5,-5" />
<ContentPresenter VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
<!-- Expander style -->
<Style TargetType="Expander">
<Setter Property="Foreground"
Value="{StaticResource ExpanderHeaderTextColor}" />
<Setter Property="Template">
<Setter.Value>
<!-- Control template for Expander -->
<ControlTemplate TargetType="Expander">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Name="ContentRow"
Height="0" />
</Grid.RowDefinitions>
<!--Header Area-->
<Border Name="Border"
Grid.Row="0"
Background="{StaticResource headerGradientBrush}"
BorderBrush="{StaticResource ExpanderBorderBrush}"
BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<!--Rectangle in the header-->
<Border Grid.Row="0"
Background="{StaticResource ToggleButtonRectangleBrush}"
BorderBrush="{StaticResource ExpanderBorderBrush}"
Margin="-4,2,2,2"
Width="10"/>
<!-- The following puts the toggle button in the right hand column, just like I want! -->
<ToggleButton Grid.Column="2"
IsChecked="{Binding Path=IsExpanded,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
OverridesDefaultStyle="True"
Template="{StaticResource ExpanderToggleButton}"
Background="{StaticResource ToggleButtonBackgroundBrush}" />
<ContentPresenter Grid.Column="1"
Margin="5"
ContentSource="Header"
RecognizesAccessKey="True" />
</Grid>
</Border>
<!--Content Area-->
<Border Name="Content"
Grid.Row="1"
Background="{StaticResource ContentAreaBackgroundBrush}"
BorderBrush="{StaticResource ExpanderBorderBrush}"
BorderThickness="1,0,1,1"
CornerRadius="0,0,3,3">
<ContentPresenter Margin="4" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded"
Value="True">
<Setter TargetName="ContentRow"
Property="Height"
Value="{Binding ElementName=Content,Path=DesiredHeight}" />
<Setter TargetName="Border"
Property="BorderBrush"
Value="{StaticResource ExpanderBorderBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
Thank you.
Everything makes sense in someone's mind
|
|
|
|
|
For Arrow Direction Change you can Use ControlTemplate.Triggers in ToggleButton ControlTemplate
<Color x:Key="Color4">Orange</Color>
<SolidColorBrush x:Key="ToggleButtonUpArrowBrush" Color="{StaticResource Color4}" />
<ControlTemplate x:Key="ExpanderToggleButton" TargetType="{x:Type ToggleButton}">
<Grid Width="16" Height="16">
<Path Stroke="{StaticResource ToggleButtonArrowBrush}"
Data="M 3,4 l 5,5 5,-5" />
<Path Stroke="{StaticResource ToggleButtonArrowBrush}"
Data="M 3,7 l 5,5 5,-5" />
<ContentPresenter VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="{TemplateBinding Content}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Data" TargetName="arrow1" Value="M 3,9 l 5,-5 5,5"/>
<Setter Property="Data" TargetName="arrow2" Value="M 3,6 l 5,-5 5,5"/>
<Setter Property="Stroke" TargetName="arrow1" Value="{StaticResource ToggleButtonUpArrowBrush}"/>
<Setter Property="Stroke" TargetName="arrow2" Value="{StaticResource ToggleButtonUpArrowBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
And For the Left most Rectangle rather than using a Border use a rectange & use its fill property like
<Style TargetType="Expander">
<Setter Property="Foreground" Value="{StaticResource ExpanderHeaderTextColor}" />
<Setter Property="Template">
<Setter.Value>
<!-- Control template for Expander -->
<ControlTemplate TargetType="Expander">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Name="ContentRow" Height="0" />
</Grid.RowDefinitions>
<!--Header Area-->
<Border Name="Border" Grid.Row="0" BorderBrush="{StaticResource ExpanderBorderBrush}"
BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<!--Rectangle in the header-->
<Rectangle Grid.Row="0" x:Name="LeftPanel" Fill="{StaticResource ExpanderBorderBrush}" Width="10" HorizontalAlignment="Left"/>
<!-- The following puts the toggle button in the right hand column, just like I want! -->
<ToggleButton Grid.Column="2" IsChecked="{Binding Path=IsExpanded,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}"/>
<ContentPresenter Grid.Column="1" Margin="5" ContentSource="Header" RecognizesAccessKey="True" />
</Grid>
</Border>
<!--Content Area-->
<Border Name="Content"
Grid.Row="1"
BorderBrush="{StaticResource ExpanderBorderBrush}"
BorderThickness="1,0,1,1"
CornerRadius="0,0,3,3">
<ContentPresenter Margin="4" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded"
Value="True">
<Setter TargetName="ContentRow"
Property="Height"
Value="{Binding ElementName=Content,Path=DesiredHeight}" />
<Setter TargetName="Border"
Property="BorderBrush"
Value="{StaticResource ExpanderBorderBrush}" />
<Setter TargetName="LeftPanel" Property="Fill" Value="{StaticResource ToggleButtonUpArrowBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Hope this is what you were looking for.
"The difference between who you are and who you want to be is what you want to do.... And what you have to do to get where you want to be
may not be pretty or may not come easy..."
"When I get sad, I stop being sad and be awesome instead." - Barney Stinson (from "How I Met Your Mother") - lewax00
|
|
|
|
|
Should be useful to the OP.
|
|
|
|
|
That worked perfectly. Thank you!
Everything makes sense in someone's mind
|
|
|
|
|
1) Anyone have a decent explantion of how Paths work? I have been researching it and it's still confusing.
2)
I found this example:
<Path Fill="SlateGray"
Data="M 2.5,5 l 10,0 l -5,6 Z" />
which draws a small down-facing arrow. How do you turn it so it's facing up?
Everything makes sense in someone's mind
|
|
|
|
|
I suppose it's easiest to explain how the Path statement works if we take your example.
First of all, let's see what M 2.5, 5 does? This moves the starting point to a point that is at 2.5, 1 relative to the owning container.
Next, l 10, 0 draws a line that starts at the point we specfied above, and ends at the point 10, 0.
Finally, l -5,6 Z draws the path from the point at 10, 0 and ends at -5,6. The Z tells the renderer to close the shape, so a line is drawn to the point that we started off with.
|
|
|
|
|
Thanks.
this[^]. Reading it now
Everything makes sense in someone's mind
|
|
|
|
|
Ok, I got it now.
BTW, is it possible to change a path using a trigger?
Everything makes sense in someone's mind
|
|
|
|
|
Of course it is. You'd have to supply a completely new Data if that's what you were trying to achieve, but it is certainly doable.
|
|
|
|
|
A path is a geometric representation of a figure.
For e.g M stands for move or startpoint. M or m can both indicate different things. V would mean a vertical line.
This[^] does explain the syntax in little detail - however, using Expression Blend is actually a much easier option to generate paths[^].
|
|
|
|
|
In my view I have a data template with a button in it:
<Button x:Name="SelectionToggle"
Command="{Binding SelectionToggleCommand, Mode=TwoWay}"
Grid.Column="1"/>
The output window shows that "SelectionToggleCommand" is not found on the model. How do I properly bind this command to the viewmodel?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
One of the wonderful thing about WPF is that Command properties can bind to any class that implements ICommand. Typical examples are Josh Smith's RelayCommand or PRISMs DelegateCommand. Suppose that you have RelayCommand, then you would hook it up like this:
private RelayCommand selectionToggleCommand;
public RelayCommand SelectionToggleCommand
{
get
{
if (selectionToggleCommand == null)
{
selectionToggleCommand = new RelayCommand(SelectToggle, CanSelectToggle);
}
return selectionToggleCommand;
}
}
private void SelectToggle(object o)
{
}
private bool CanSelectToggle(object o)
{
return true;
}
|
|
|
|
|