When writing WPF/Silverlight applications, I sometimes struggle when determining whether or not a property should go inside a style or be left directly on the element. What guidelines do you use when deciding?
In XAML, what "guidelines" should I use when deciding whether or not a property should go in a style?
186 views Asked by Jordan Parmer At
2
There are 2 answers
0
Prince Ashitaka
On
Very good question. There are two situations where I move a property into a style.
1) Over Crowded Properties - Over crowded properties are nothing but, too many properties for customizing an element. Say for example. If you have a text block and want to customize almost all the properties. Then, it'll reduce the readability. That too if it has somethings like triggers. It'll be too much crowded. By that time, I used to move them to a style.
2) Repeatedly Used Styles - This is obvious case, if I want to apply a same set of properties to be applied for a control. Usually we do this by x:key or TargetType.
HTH
Related Questions in WPF
- Sorting a List by its property renames all the objects in the List
- Can't open new instance of another window in my app, in WPF .NET 8
- Binding forecolour and ToolTip to a DataGrid
- how to create Infinite Upgrades in a clicker game
- Try Catch exception is not catching the unhandled exception
- Assigning an object to another doesn't raise PropertyChanged event in WPF
- Masking input in TextBox
- What should I do if Visual Studio has a restriction on creating files with a long name or a long path to these files?
- reading configuration file (mytest.exe.config)
- WPF Windows Initializing is locking the separated thread in .Net 8
- How to bind to the DataContext ViewModel of another view?
- mouse coordinates in image go below 0 and above width
- WPF pop up is behaving differently in English language PC and Japanese language PC
- Multi level project reference using dll
- Unable to unzip archive .NET framework
Related Questions in SILVERLIGHT
- ServiceReferences.ClientConfig use basicHttpsBinding or similar
- How to draw and show map in in ArcGIS C# Silverlight Application
- ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol invoke system crash on Unhandled Error in Silverlight Application
- OpenSilver 'Tapped' event not triggered on phone
- Debugging Silverlight with Microsoft Edge
- Where to download Silverlight Developer Runtime nowadays?
- Where can I download RiaServices.msi nowadays?
- How to build old Silverlight project in Azure DevOps?
- reading of barcodes are badly interpreted in silverlight app with edge
- StringFormat doesnt change number in Silverlight <telerik:GridViewDataColumn>
- Migrate Silverlight check for ElevatedPermission to ASP.NET MVC
- How do I install Silverlight now that it has been discontinued?
- OpenSilver and Dispatcher.CheckAccess
- Port Silverlight Storyboard to WPF
- Silverlight bing maps component are no longer working
Related Questions in XAML
- Can't open new instance of another window in my app, in WPF .NET 8
- Visual Studio throwing DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION when I try to add a log
- Deeplinking in .net Maui "Window was allready created"
- MauiApp crashes only in release mode at sideswitch android.os.DeadObjectException
- Move .net maui contents below the drawer when it's opened
- Both `TouchBehavior.CommandParameter` and `TouchBehavior.LongPressCommandParameter` are always passed as `null` to `Command` and `LongPressCommand`
- How do I change the size of a window?
- How can I force a .NET MAUI ContentView to fill the entire remaining space of its FlexLayout parent?
- How can I get this ComboBox to bind, populate the dropdown and write back selected value on update?
- MAUI-Animating each element of a BindableLayout
- Correctly set RadioButtonGroup for CollectionView in .NET MAUI
- Multiple color schemes depending on build configuration in WPF-application
- Select XAML file based on build configuration (Visual Studio 2022, WPF)
- The type was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built
- How can I tell if a control is actually Visible in UWP?
Related Questions in UI-GUIDELINES
- Will using affine transform to shrink UIStepper as UIBarButtonItem disqualify my app?
- Need functionality of smart-Guides in Angular like jQuery
- Proper Guidelines for Show / Modal Presentation in iOS 13?
- Sizing WPF controls based on Windows design guideline recommendations
- How to set vim highlight ColorColumn guideline transparency?
- Recommended control or page flow for iOS app
- Appropriate icon for Windows 8 installer
- static UI analysis with my own grammar rules (want to make eclipse android visual UI guidelines checker)
- guidelines for opening safari from an iPhone app
- Present data to user as Activity or Dialog
- Windows forms - inactive highlight color
- Navigation bar and Toolbar in ipad app at top of screen - apple's approval?
- Testing Tool for UI Style Guides?
- UINavigationController and navigation bar with cross-hierarchy jumps
- Is there any website showcasing all of the available UI components and widgets with source code?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I think it generally comes down to style reuse and overall project organization.
If it is a style you are going to be reusing across many different elements in a control (such as Brushes) or even in many different controls in your project you are obviously going to want to pull it out into its own resource. For better organization you probably even going to want to put these shared styles in their own resource dictionary file and used MergedDictionaries to pull them in to different controls. You can actually create some pretty useful cascading effects between different styles using the
BasedOnattribute as well.When it comes down just a "one-off" feature of a specific element I think its fine to keep style attributes directly on the element. If it doesn't need to be shared and the style is unique to the one element (specific Border, Margin, etc) it is much easier and more readable to keep it directly on the element.