User control refactoring (WPF)

X

XJ

Hi Expert,
i'm doing some program for my project which using WPF, to create
my application more managible i would apply "user control" concept for
my project for each section of my workspace.

to make my workspace more flexible, all the "namespace" and "user
control" name will store into DB, once user launch my application,
base on different user setting i'm able to load for different user
control accordingly base on on the DB record.

i have 2 question now:

1. How to declare those user control "name space" thru codebehind ?
right now i only able to code my "name space" at XAML
example: xmlns:uccustom="clr-namespace:WpfApplication1"

2. How to declare the "user control" name thru codebehind?
right now i also have to declare the user control name at XAML
example: <uccustom:UserControl1 Margin="20,0,-605,-236.5"
Height="188" VerticalAlignment="Bottom"/>

* so far i only know to do the setting from XAML, but which is not
enough flexible due to setting concept.please advise , thanks


best regards
 
X

XJ

[...]
* so far i only know to do the setting from XAML, but which is not
enough flexible due to setting concept.please advise , thanks

If you can't automatically generate the XAML to layout your UI  
conditionally as you like, you can just write C# code to do it.  I presume  
that's why you're posting here in the C# newsgroup.

Beyond that though, it's not clear what you're asking.  You can design  
your own UserControl sub-class, and then in the code that goes with your  
XAML, just check the database record you care about and conditionally  
add/place whatever UserControl instances are appropriate to that database 
record (after instantiating them explicitly, of course).

I don't know that there's really any specific answer to your #2 question; 
it seems to me that you'd just use XAML to define each UserControl  
sub-class as appropriate, as you're already doing.  For the #1 question, I  
don't understand why the default name space isn't appropriate, nor why you  
care, given the rest of what you wrote.  But assuming it's important, it  
seems like you could just explicitly write a new namespace as appropriate 
for your needs (you have to change it in both the .xaml and the .cs file)..

Pete

Hi Pete,
thanks for your reply, yes, i use C# to develop my
application.
try to imagine, i develop a dockPanel inside my WPF windows ,
which is open for my colleage to post their own "user control" , for
sure my colleage have to develop their own XAML file ( and code
behind) and make as dll , once they done for their User control, they
will goto database to provide the user control name space and user
control name, base on the login , my dock Panel windows will trigger
"their" own user control from my dock panel.

i have no experience to write the code behind to execute and
build the "user control" at runtime.

best regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top