|
Using an attached property to store the original value works quite well. You probably wouldn't want to declare the attached property in a window as I have done.
<Button x:Name="b" Click="b_Click" local:Window1.OriginalContent="OriginalValue" />
void b_Click(object sender, RoutedEventArgs e)
{
var newValue = "New Value";
var original = GetOriginalContent(b);
b.Content = b.Content.Equals(newValue) ? original : newValue;
}
#region OriginalContent Attached Property
public static readonly DependencyProperty OriginalContentProperty = DependencyProperty.RegisterAttached("OriginalContent", typeof (object), typeof (Window1), new UIPropertyMetadata(Changed));
private static void Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((ContentControl) d).Content = e.NewValue;
}
public static object GetOriginalContent(DependencyObject d)
{
return d.GetValue(OriginalContentProperty);
}
public static void SetOriginalContent(DependencyObject d, object value)
{
d.SetValue(OriginalContentProperty, value);
}
#endregion
|
|
|
|
|
Interesting idea ...
When I get to work in a couple of hours I'll dig out the code that I used to get at the _effectiveValues and see if anything can be done with that. I'll post it here as well.
Urgh, I feel sick just thinking about it!!
Thanks for this Dave.
|
|
|
|
|
Indeed, I was looking through the results of the LocalValueEnumerator and trying ReadLocalValue etc ...
I've had lots of fun in the past coding round the _effectiveValues array. Its really not pretty code at all. According to one thing I read this whole area of WPF is 'unfinished'. I just hope that in the next version some of this stuff is 'fixed' or 'completed'.
|
|
|
|
|
I've just tried this:
object _buttonContent = btnLoadData.ReadLocalValue(ContentProperty);
if (_buttonContent != DependencyProperty.UnsetValue && _buttonContent != null)
{
Type tx = _buttonContent.GetType();
PropertyInfo pinfo = tx.GetProperty("Content");
if (pinfo != null)
{
object objPropertyValue = pinfo.GetValue(_buttonContent, null);
string BtnContent = objPropertyValue as string;
}
}
No luck, as you say they both count as local values. There doesn't seem to be any way of 're-reading' the XAML Content="Original Value" ...
That just seems absolutely NUTS to me ... it must be doable ... surely ...
|
|
|
|
|
Hi,
i'm quite nobbie with C# and WPF but it seems as very interesting to me...
here is my question, how can i make custom main frame look with wpf
i know for the property "WindowStyle..." but i need to change default style...
is ti possible to override the default style form and how?
the reason is simple, i want my application to look the same on every windows version with every
|
|
|
|
|
You make so the window has no border and then you can WPF elements to alter the appearance of the window. If you want to make the windows look the same: create one window with the appearance you want, then make the other windows inherited from the original one.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Ok,
how can i make all other elements look the same
like chack boxes, text fields, dropDown lists etc ???
|
|
|
|
|
You can define styles for the controls that will be automatically applied. If you want to do this, I would expect that you have Blend installed - it makes things easier for you.
|
|
|
|
|
i'm searching all around codeproject for some article about exactly that but i can't find it :$
if you know any, could you provide me with link please
|
|
|
|
|
Do an article search for articles by Josh Smith or Sacha Barber.
|
|
|
|
|
i already found some of their articles,
thank you..
however, it's seemed to me that they are too much concrete about topics
but i'll try to look deeper in to WPF on MSDN
thank you
|
|
|
|
|
Your best bet would be to buy a good book on WPF to learn about control styling. I would suggest any of the WPF books from Apress, they have been great additions to my book collection.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
|
Josh Smith and Sacha Barber write BRILLIANT articles on WPF ... study them intently ...
|
|
|
|
|
I have an ASP.NET control that I bought and I want to use it inside a SL application. Does anyone know how can I do that?
Thanks.
|
|
|
|
|
You can't use ASP.NET in XAML so does Silverlight. But you can show ASP.NET control over Silverlight control. It's all about CSS and HTML thing. Just overlay it on Silverlight DIV.
|
|
|
|
|
Hello there,
I am new to silverlight but i have already had the idea that it is much like Flash.
In this case is it possible to develop a whole offline desktop application
using Silverlight ?
Is that possible too when my target is Windows Mobile ?
Thank You in advance.
Our Philosophy, Mohammed Baqir Al Sadr
|
|
|
|
|
It's possible if you are using Isolated Storage. but actually, Silverlight is not designed for offline application...
|
|
|
|
|
http://silverlight.net/forums/t/22276.aspx[^]
So I still do'nt know the correct information, indeed. Anyway..
It's all becuase I am seraching how to do animation and transparency effects for Windows Mobile application.
Our Philosophy, Mohammed Baqir Al Sadr
|
|
|
|
|
Friends, Please help!
I am writing a WPF application using .net 3.5 and VS 2008. Trying to achieve drag and drop operation.
1. I initiate the dragdrop operation by DragDrop.DoDragDrop in the TreeviewItem's mouseMove event. The second parameter in the DoDragDrop method has a object.
2. I am trying to drop this data onto a textbox. I have coded Drop and DragOver events of the textbox. And I have set the AllowDrop property of the textbox to true.
3. I get the symbol operation not allowed when I am on the textbox. I also notice that neither my dragover and drop events are getting fired.
4. I change the textbox to textblock everything works fine.
5. I also tested this with a ListBox and it works fine too.
6. I need to make this work for textbox, can somebody please help? What am I doing wrong?
I am including my code in the following code block...
void REQNode_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
TreeViewItem tvi = sender as TreeViewItem;
dragContext = tvi.Tag as REQRequirement;
DragDrop.DoDragDrop(tvi,dragContext, DragDropEffects.Copy);
}
}
private void txtPostCond_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(REQRequirement)))
{
e.Effects = DragDropEffects.Copy;
}
else
{
e.Effects = DragDropEffects.None;
}
}
public void txtPostCond_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(REQRequirement)))
{
REQRequirement req = (REQRequirement)e.Data.GetData(typeof(REQRequirement));
txtPostCond.Text = req.Description;
}
}
Please Help!
Thank you,
Srini.
|
|
|
|
|
The simplest solution is to start the dragdrop with this line
"DragDrop.DoDragDrop(tvi, dragContext.Description, DragDropEffects.Copy);"
I assume that Description is a string. You can than just forget about the other two events. The textbox already knows how to handle the dragover and dragdrop events with strings.
This is what is causing the behaviour. The textbox already has a command binding for the paste command which handles the two events and marks them as handled.
If you want to drag drop other things than string, you'll have to handle the events before textbox does, and to mark them as hadled so it can't override your settings:
TextBox AllowDrop="True" Drop="TextBlock_Drop" PreviewDragOver="TextBlox_DragOver" PreviewDragEnter="TextBlox_DragOver"
private void TextBlox_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Button)))
{
e.Effects = DragDropEffects.Copy;
}
else
{
e.Effects = DragDropEffects.None;
}
e.Handled = true;
}
|
|
|
|
|
This is excellent! Thank you very much for your response. You are right I actually worked with preview_dragenter earlier and it was working. It didn't make sense to me. But your response explains it all. Thank you very very much!
- Srini.
|
|
|
|
|
Hi again!
WPF again.. [sight]
I have a simple WPF grid. Furthermore I have two different types of items in this grid, a self defined which inherits from TextBlock and contains PositionX and PositionY - these are my main controls; and TextBlocks whcih do the role of column and rowheaders
---------------
|0|1|2|3|4|5|6|
|1|_|_|_|_|_|_|
|2|_|_|_|_|_|_|
|3|_|X|_|_|_|_|
---------------
So I click on x and with e.Originalsource casted to my Class i get the information inside my object.
What I need now are the Tooltips of the two headers, in this case Tooltip of Textblock in cell 2/0
and the ToolTip of cell 0/3.
As mentioned before those are Type of TextBlock.
A foreach iteration does not work, as the Headers are created this way:
for (int i = 0; i < 65; i++)
{
TextBlock b1 = new TextBlock() { Text = i.ToString(), ToolTip = GetInformationFromXML(i, 0) };
Grid.SetColumn(b1, 0);
Grid.SetRow(b1, i);
g.Children.Add(b1);
if (i != 0)
{
TextBlock b2 = new TextBlock() { Text = i.ToString(), ToolTip = GetInformationFromXML(i, 0) };
Grid.SetColumn(b2, i);
Grid.SetRow(b2, 0);
g.Children.Add(b2);
}
}
So there is no unique name at all.
What I get is
MyObject o = (MyObject)e.OriginalSource;
int X = o.GridPositionX;
int Y = o.GridPositionY;
What I need is
TextBlock tb1 = (TextBlock)grid.GetItem(X,0);
TextBlock tb2 = (TextBlock)grid.GetItem(0,Y);
grid[X][0] does not work.
Can someone please explain me how to retrieve these?
Thank you in advance,
eza
|
|
|
|
|
What you are doing is quite strange ... it's not a good idea to keep important data in the tooltip property.
private UIElement getElement(int column, int row)
{
foreach (UIElement e in MyGrid.Children)
if (Grid.GetColumn(e) == column)
if (Grid.GetRow(e) == row)
return e;
return null;
}
You will have to cast the UIElement to textblock to get the tooltip.
|
|
|
|
|
Thank you for your solution.
Well, concearnig the data in the tooltip:
this project represents a 128x128 matrix, so I cannot use full names for the headers - you couldn't read them any more.
So I thought I pass the full name to the tooltip and retrieve them when hoovering over an item.
the item generates a tooltip which shows the full name of the row and the full name of the column.
The names of the single devices (a.ka headers) are gnereated out of an xml file, so I don't want to open/read/close it every time I create an item (which represents a line between two devices). Either I don't think it's necessary to hold the items in a Dictionary, just for this.
I could use the Tag Property instead, anyway I just need the Text (the full name) of the device.
Do you have any better ideas how this can be done? I would be more than happy to hear them.
Thank you,
eza
|
|
|
|