|
I'm looking to inherit from some standard WPF controls, including windows, buttons and a few others. I wish to add some functionality to them that will be common between several controls. My plan was to create an interface for the common functionality, and implement this interface on the required controls. The problem i am getting is that i cannot specify an access modifier on the interface implementations so that they are made available as designer editable properties.
For example i created an interface as follows:
public interface iSecurityControled
{
SecuritySettings.ProgramAreas ProgramArea { get; set; }
SecuritySettings.DisabledActions DisabledAction { get; set; }
}
public class SecuritySettings
{
public enum ProgramAreas
{
None,
Client,
Development,
Block,
Accounts
}
public enum DisabledActions
{
None,
Hide,
Disable
}
}
I then created a class inheriting from the WPF window class and implemented the above interface
public class Form:System.Windows.Window, Interfaces.iSecurityControled
{
#region iSecurityControled Members
private SecuritySettings.ProgramAreas _ProgramArea = SecuritySettings.ProgramAreas.None;
SecuritySettings.ProgramAreas iSecurityControled.ProgramArea
{
get
{
return _ProgramArea;
}
set
{
_ProgramArea = value;
}
}
private SecuritySettings.DisabledActions _DisabledAction = SecuritySettings.DisabledActions.None;
SecuritySettings.DisabledActions iSecurityControled.DisabledAction
{
get
{
return _DisabledAction;
}
set
{
_DisabledAction = value;
}
}
public int MyProperty { get; set; }
#endregion
}
My problem is that if i add the public modifier to the properties i get the following error message:
The modifier 'public' is not valid for this item.
I have tried to add the public modifier to the interface declaration and get the same error. This means that the property is not visible in the designer, however the MyProperty is. To sanity check my thinking i have re done this code as a standard winforms project and it works just as i want it to.
Not sure if this will be of any use but it is possible to use the following code to set the properties,
((iSecurityControled)this).DisabledAction = SecuritySettings.DisabledActions.Disable;
but this is not achieving the design time way of working that i am aiming to achieve.
If any one could point me in the direction of a solution it would be greatly appreciated.
|
|
|
|
|
Change
SecuritySettings.DisabledActions iSecurityControled.DisabledAction {
get { return _DisabledAction; }
set { _DisabledAction = value; }
} to
public SecuritySettings.DisabledActions DisabledAction {
get { return _DisabledAction; }
set { _DisabledAction = value; }
} You need to do the same for the other property as well. Basically, you've supplied an explicit interface definition there - when an implicit one will suit your needs.
|
|
|
|
|
thanks for the quick and helpful response. Your solution worked a treat.
I guess as WPF is new to me i was assuming it was to blame for something that was just a simple mistake of mine.
|
|
|
|
|
Don't worry about it - we all started off fearing WPF; soon the love comes.
|
|
|
|
|
I have a small button placed upon a bigger button. Both buttons have their own style. Both buttons work independently with their IsMouseOver/IsPressed styles. My requirement is that Click on big/small button should evoke both buttons, also mouseEnter/Leave on big button should evoke both buttons. As small button is placed on big button and user will not be able to see that there are two buttons, mouseLeave/Enter on small button should not evoke a new response.
I don't want to make any change in styles, because that will complicate the thing. I can make change in XAML where i am setting the style or in the code-behind CS file. I assume that it is possible with XAML only, and without writing any code in C#.
A reply with a bit code(XAML/C#) will help a lot.
modified on Wednesday, August 25, 2010 4:40 AM
|
|
|
|
|
Hi,
I have listView, which has a GridView Column ,having DataTemplate which has ComboBox, I m binding the listview's Colums using a collection , but this combo alone with another collection . But its not working .
//resource
<objectdataprovider x:key="myList" objecttype="{x:Type local:NameList}">
<listview>...
<gridviewcolumn.celltemplate>
<datatemplate x:name="myDataTemp">
<combobox x:name="Web_Combo" selectedvalue="{Binding Path=MatchedValue, Mode=TwoWay}"
="" itemssource="{Binding Source={StaticResource myList}}" width="100" height="25">
code :
namespace N
{
public class NameList : List<string>
{
public NameList()
{
//this.Add("Name");
//this.Add("Name1");
}
}
public partial class Window5 : Window
{
public NameList pp
{
get;set;
}
public Window5()
{
this.InitializeComponent();
pp = new NameList();
pp.Add("dfgdf");
pp.Add("ggf");
}
}
}
Here if i hard code values inside consturctor its working , if i create object of this class and add items to it. its not binding.
pl let me know how to bind the object of the colletion to combo
thanks
|
|
|
|
|
You're adding elements to the wrong list. You need to get a reference to "myList" and add the elements to that, not create a new one in the code-behind.
Check out the FindResource function, and use that to get "myList".
|
|
|
|
|
Thanks for the info, It worked after I use FindResource.
But I have one more trouble, I have a button called ResetAll, Onclick of it, should reset all the Combo indexs to 0 or -1 in the listview. As the combo is built added part of datatemplate in each listview item. Can u throw me a way to do this. pl find the reference code below
Xmal :
<usercontrol.resources>
<objectdataprovider x:key="myList" objecttype="{x:Type local:NameList}">
<objectdataprovider x:key="myList" objecttype="{x:Type local:TaskList}">
<grid>
<listview x:name="ListView_Web" selectionmode="Single"
datacontext="{Binding Source={StaticResource TaskList}}"
issynchronizedwithcurrentitem="True" itemssource="{Binding}"
alternationcount="2" background="#FFD9D9D9">
<listview.view>
<gridview columnheadercontainerstyle="{DynamicResource CustomHeaderStyle}"> <gridviewcolumn header="Name" width="70" displaymemberbinding="{Binding Path=Name}">
<gridviewcolumn header="Age" width="100" displaymemberbinding="{Binding Path=EmpdId}">
<gridviewcolumn header="StateList" width="150">
<gridviewcolumn.celltemplate>
<datatemplate x:name="myDataTemp">
<combobox selectedvalue="{Binding Path=SelectedValue, Mode=TwoWay}"
="" itemssource="{Binding Source={StaticResource myList}, Mode=OneWay}" width="100" height="25">
Code :
Namespace N
{
public class NameList : List<string>
{
public NameList()
{
}
}
public class Window1
{
Window1()
{
ObjectDataProvider objectDataProvider = this.TryFindResource("myList") as ObjectDataProvider;
NameList nameList = objectDataProvider.Data as NameList;
AddItemsToCombo(ref nameList );//this adds items to combo from webserivce
}
On_ResetButtonClick()
{
//How do I reset the comboItems of each listview item.
}
}
Thanks in adavance
|
|
|
|
|
You shouldn't be trying to edit the combo boxes directly, especially if they're in a DataTemplate.
Instead, go to whatever they're bound to, and set THAT to null. If your binding is correct, the combos will automatically update themselves.
Remember that either the bound object needs to implement INotifyPropertyChanged, or the bound property has to be a DependencyProperty... Otherwise the binding won't be triggered.
|
|
|
|
|
Use merged resource dictionaries. See here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Hi,
I have hashtable that contain wpf and telerik controls,
and I need to serialize it to xml file.
I found this code for wpf controls:
string savedButton = XamlWriter.Save(origianlButton);
File.WriteAllText(@"C:\test.xml", savedButton);
but it doesn't work for telerik controls, it stuck and I get this error:
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
Is there any other way to do that?
Thanks in advance.
modified on Tuesday, August 24, 2010 2:56 AM
|
|
|
|
|
Try to Serialize the Object.[[^]]
|
|
|
|
|
I have a ListBox whose Height is bound one way to source. As you can see from the XAML below, the listbox is supposed to take up all the space available to it, and it's height is not initialised to anything in C# code.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding PhotoList}" Grid.Row="0" Height="{Binding Path=listBoxH, Mode=OneWayToSource}">
</ListBox>
</Grid>
My problem is that I need to get a numerical value for listBoxH in the code behind (bounded code, it's actually the ViewModel of my UI). But this value is double.NaN . This is expected as the Height/listBoxH is not "set" anywhere, but is there a way to get the ActualHeight of the ListBox?
I need to get the current height of the ListBox, use it do a calculation which decides what to display in the ListBox.
I can't directly reference the ListBox in C# code as it doesn't belong to the same class, and this is not the approach I want to take.
Workarounds, anyone?
|
|
|
|
|
Most (all?) controls that have a Height also have an ActualHeight property. Not sure if you can bind to it. You might be able to use a size change event to detect when the size has changed then then get the value of ActualHeight.
|
|
|
|
|
Thanks for the tip. I found that changes to ActualHeight could be used as a trigger. I've tried to use an event trigger, and am currently stuck. Here's what I've done:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding gridHeight}" />
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding PhotoList}" Grid.Row="0" >
<ListBox.Style>
<Style>
<Style.Triggers>
<EventTrigger RoutedEvent="SizeChanged">
<!-- Set {Binding tabHeight} to ActualHeight here -->
</EventTrigger>
</Style.Triggers>
</Style>
</ListBox.Style>
</ListBox>
</Grid>
The problem is, I can't figure out how to tell it to update tabHeight once the event is triggered. I initially thought I could use a Setter to update {Binding Path=tabHeight} . But that doesn't seem to be the case.
Suggestions are much appreciated 
|
|
|
|
|
Hi,
I have WPF app and I need to save the data(Hashtable) into the Cache
for one day,also if the app was closed.
I try to use ObjectCache but it cleaned in every running.
May anyone have a solution,
Thanks a lot.
|
|
|
|
|
What Cache? If you are trying to save data, you may consider writing out as XML, or saving it to a database or serializing it to file. The choice depends on your application needs and architecture.
"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
|
|
|
|
|
Hi,
Thanks for fast reply .
I have an Hashtable that contains objects.
And I want to save it not matter what.
I will glad if you can explain to me what is the better way to do it(XML or file)?
Thanks again.
|
|
|
|
|
If the objects are all serializable, then it's a simple matter to serialize them to file using something like the XmlSerializer .
"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
|
|
|
|
|
Hi,
Thanks again.
1)Can I serialize only the Hashtable?
Or I need to serialize every object one by one?
2)I have one Hashtable that its objects don't serializable,
Is there any way to cache it?
Thanks a lot.
|
|
|
|
|
Serializing the hash table should serialize the component objects. Remember that they need to be serializable objects in their own right for this to work.
"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,
I have linq to sql objects and I found that I can serialize the sql by putting
this: < Database ... Serialization="Unidirectional > on the dbml file.
How can I serialize Hashtable that contain objects like that?
Thanks a lot.
modified on Monday, August 23, 2010 2:43 AM
|
|
|
|
|
Why would you want to? This indicates that the data is already saved to the database - meaning you don't need to save it to a different storage medium.
"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 sql query and I want to save every running the row that selected from each table.
I found solution for that .
I mark the dmbl as serializable with
<Database... Serialization="Unidirectional">
and than use NetDataContractSerializer object to serialize\deserialize.
Now, I have another problem, I want to save also the search criterions,
every search I save the controls with the search criterions in hashtable,
and I want to save it also at xml but the controls are not serializable(I use wpf and telerik controls).
Is thare any way to do it?
Thanks again.
|
|
|
|
|
I just want to get the text in elements like the id, name, and lastactive from an xml file like this ( http://www.dreamincode.net/forums/xml.php?showuser=34 ) into a textbox or anything that would just display in a simple way, but I haven't been able to find anything that explains that level of it. How can I do this?
-- Modified Sunday, August 22, 2010 3:07 AM
|
|
|
|