|
Each letter will be in its own Run and you would style them individually.
|
|
|
|
|
Thank's for your reply. Run adds a space so I get "H e l l o"
|
|
|
|
|
Use a Span tag for each character:
<Span Foreground="Red">H</Span><Span Foreground="Orange">e</Span><Span Foreground="Yellow">l</Span><Span Foreground="Green">l</Span><Span Foreground="Blue">o</Span>
|
|
|
|
|
Span adds leading spaces too
|
|
|
|
|
I tested it! ... (in WPF, not Silverlight)
Of course, there can be no spaces between the Span tags (end of one Span and beginning of the next).
Just as I showed in posting above...
|
|
|
|
|
Ah - I just found that out too - it's the same with Run
Thanks for your help
|
|
|
|
|
You were right - but all the Run elements have to be on the same line.
Thanks for your help<
|
|
|
|
|
hi.
I'm trying to insert a stackpanel into a columndefinion programmatically
I do this:
two colored rectangles
stackpanel.Children.Insert(0, rectng);
stackpanel.Children.Insert(1,recText);
ViewerGrid.ColumnDefinitions[index].SetValue(ContentProperty, stackpanel);
i don't receive nothing at the grid. empty at all.
maybe the way i work with the columndefinitios is not the way that should.
thanks.
|
|
|
|
|
The column information is an attached property. I think you want something like:
stackpanel.Children.Insert(0, rectng);
stackpanel.Children.Insert(1,recText);
ViewerGrid.Children.Add(stackpanel);
Grid.SetColumn(stackpanel, index);
|
|
|
|
|
|
hi,I have a grid that background is transparent,
how i can save the image that the grid is display?
|
|
|
|
|
Hello guys,
i have a Treeview with CheckBox and TextBlock, and i wanna know how i can change the backgroundcolor for the textblock and for each parentnode in the tree when the checkbox is checked?!
I have try to set trigger and setter, but i dont have the right solution.
Can anyone please help me?
friendly regards
|
|
|
|
|
I have a window with 2 splitters. Thus makes up a left pane, a tab area, and a right pane. Think Visual Studio
The left splitter works fine, but the right does not. Here's the XAML. Paste into a window and you'll see what I mean. The spliiter is there, just all the way over to the right:
<Window x:Class="FMG.UI.WPF.Views.MainWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="350"
Width="525"
Closing="Window_Closing"
Background="LightSkyBlue">
<!--Title="{Binding Source={x:Static classes:FMGEngine.AppLongName}}"-->
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!--Menu-->
<Menu Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="5"
IsMainMenu="True">
<MenuItem Header="_File" />
<MenuItem Header="_Edit" />
<MenuItem Header="_View" />
<MenuItem Header="_Window" />
<MenuItem Header="_Help" />
</Menu>
<!--Toolbar-->
<ToolBar Name="tbrStandard"
Grid.Row="1"
Grid.ColumnSpan="5">
<Button>One</Button>
<Button>Two</Button>
<Button>Three</Button>
</ToolBar>
<!--Left Side Grid-->
<Grid Grid.Row="2"
Grid.Column="0"
HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--Search Area Grid-->
<Grid Grid.Row="0"
Grid.Column="0"
Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0"
Width="Auto"/>
<Button Grid.Column="1"
Height="24"
Width="24"/>
</Grid>
<ListBox Grid.Row="1"
Grid.Column="0"
Background="Aqua"
HorizontalAlignment="Stretch"
Width="Auto"/>
</Grid>
<!--Left Verticle Splitter-->
<GridSplitter Grid.Row="2"
Grid.Column="1"
Background="Gray"
ResizeDirection="Columns"
HorizontalAlignment="Left"
Width="10"/>
<!--Tabs-->
<TabControl Grid.Row="2"
Grid.Column="2"
Background="Salmon"/>
<!--Right Verticle Splitter-->
<GridSplitter Grid.Row="2"
Grid.Column="2"
ResizeDirection="Columns"
HorizontalAlignment="Right"
Width="10"/>
<!--Right Side-->
<Grid Grid.Row="2"
Grid.Column="4"
HorizontalAlignment="Stretch"
Background="Red">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListBox Grid.Row="1"
Grid.Column="0"
Background="SteelBlue"
HorizontalAlignment="Stretch"
Width="Auto"/>
</Grid>
<!--Status Bar-->
<StatusBar Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="4"
Height="24"/>
</Grid>
</Window>
Anyone see what's wrong?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Here's one tough question - I am suspecting Dispatcher deadlock, thus freezing the UI (after I click SaveItems button some number of times).
The following event handler "OnItemsReloaded" is triggered async from another thread ("LoadItems" thread - which holds a lock on an object "ItemsSyncRoot". Another thread ("SaveItems" thread) also competes to lock on to this object.
(So yes, LoadItems thread and SaveItems thread contending for same lock)
Here's the EMPTY Dispatcher.Invoke (Triggered by "LoadItems" thread - a background thread):
<br />
private void OnItemsReloaded(object sender, EventArgs e)<br />
{<br />
SchedulesGrid.Dispatcher.Invoke(<br />
System.Windows.Threading.DispatcherPriority.Normal,<br />
new Action(<br />
delegate()<br />
{<br />
}<br />
));<br />
<br />
return;<br />
}<br />
If I change above from "Invoke" to "BeginInvoke" - UI no longer freeze! Question is why. (Please note for debugging purpose, event handler Dispatcher delegate is empty! [So no lock in Dispatch.Invoke delegate!]
[SAME, UI don't freeze if I put a "return" before "Dispatcher" invoke!?]
I futher attempted to nail down the scope further by:
(a) Attached Visual Studio debugger to the running/freezed UI - then from Intellitrace, "Breakall"- which reveals that execution of a "Background" thread freeze on attempting to lock(ItemsSyncRoot). Since this is a background thread ("SaveItems" thread) which attempted to lock(ItemsSyncRoot) - this does NOT explains why UI freezed!
(b) Windbg - !syncblk,) then !clrstack - which pointed me to the [Dispatcher.Invoke] as stated above! But what's confusing is, I don't see why an "Empty Dispatcher Invoke" can lead to UI freezing up.
Note that from !syncblk Info=64. I used that in !clrstack command (Is this right?)
<br />
0:210> .loadby sos clr <-- This is to load SOS managed code debugger extension (From same dir as CLR)<br />
0:210> !syncblk <-- List locks, note Info=64. Next command uses this thread ID 64 to retrieve CLR stack of thread 64.<br />
Index SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner<br />
425 11f0d280 3 1 07136b68 1938 64 0279d498 ItemsSyncRoot<br />
-----------------------------<br />
Total 425<br />
CCW 7<br />
RCW 8<br />
ComClassFactory 0<br />
Free 20<br />
<br />
0:210> ~64e!clrstack <-- see what's thread 64 is doing<br />
OS Thread Id: 0x1938 (64)<br />
Child SP IP Call Site<br />
0e44d7e0 77e200fd [HelperMethodFrame_1OBJ: 0e44d7e0] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean)<br />
0e44d888 6354b5ef System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\246f1a5abb686b9dcdf22d3505b08cea\mscorlib.ni.dll<br />
<br />
0e44d8a4 6352b1ee System.Threading.WaitHandle.WaitOne(System.TimeSpan, Boolean)<br />
0e44d8c4 65addfc1 System.Windows.Threading.DispatcherOperation+DispatcherOperationEvent.WaitOne()*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\WindowsBase\d17606e813f01376bd0def23726ecc62\WindowsBase.ni.dll<br />
<br />
0e44d8f4 65adda7a System.Windows.Threading.DispatcherOperation.Wait(System.TimeSpan)<br />
0e44d90c 65aee0aa System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)<br />
0e44d954 65cc8d3d System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate)<br />
<br />
... [What the hell a empty Dispatcher.Invoke caused UI to freeze up!?]<br />
0e44d970 005763ee ...OnItemsReloaded(System.Object, System.EventArgs)*** WARNING: Unable to verify checksum for ...<br />
...<br />
<br />
0e44e6f8 6354ae5b System.Threading.ThreadHelper.ThreadStart_Context(System.Object)<br />
0e44e708 634d7ff4 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)<br />
0e44e72c 634d7f34 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)<br />
0e44e748 6354ade8 System.Threading.ThreadHelper.ThreadStart()<br />
0e44e96c 671c21db [GCFrame: 0e44e96c] <br />
0e44ec30 671c21db [DebuggerU2MCatchHandlerFrame: 0e44ec30] <br />
Note that after I changed Dispatcher.Invoke to Dispatcher.BeginInvoke the problem basically resolved. I just want to know why it happenned. (If WPF Dispatcher framework... any issue...)
I also used Steve Johnson's SOSEX debugger - scan indicated Absence of deadlock!
Confused.
REF 1:
http://ewulf84.blogspot.hk/2011/12/using-syncblk-to-debug-hung-operation.html
http://stackoverflow.com/questions/508398/detecting-deadlocks-in-a-c-sharp-application
http://msdn.microsoft.com/en-us/magazine/cc163618.aspx#S4
REF 2 - WinDbg: http://msdn.microsoft.com/en-us/windows/hardware/gg463009/
REF 3 - WinDbg cheat sheet: http://geekswithblogs.net/.NETonMyMind/archive/2006/03/14/72262.aspx
REF 4 - Steve Johnson SOSEX Debugger extension: http://www.informit.com/articles/article.aspx?p=1583957 and http://www.stevestechspot.com/SOSEXV40NowAvailable.aspx)
dev
modified 27-Nov-12 1:58am.
|
|
|
|
|
Found the answer, share it here to dispel myth Dispatcher.Invoke buggy...
thread A background thread
<br />
lock(SomeSingleton)<br />
{<br />
LoadItems(..) --> This will trigger event "ItemsReloaded", and one UI thread handler handles this. Problem is, "SaveItems" button clicked after initial lock to SomeSingleton but before "ItemsReloaded" fired.<br />
}<br />
UI Thread handler for "ItemsLoaded":
<br />
...<br />
ItemsGrid.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Background,<br />
new Action(<br />
delegate()<br />
{<br />
}<br />
...<br />
Thread B (UI Thread)
void btnItemsSaved_Clicked(...)
{
lock(SomeSingleton) // Block by thread A, thus hanging UI thread.
{
// blocked indefinitely as Thread A cannot return until "ItemsLoaded" (thus its UI handler) is fired.
}
return;
}
Hope it helps.
What's INTERESTING though, is Windbg pointed me to lock statement in THREAD-A, whereas, if I attached Visual Studio debugger (with Intellitrace), it lead me straight to lock statement in THREAD-B
Also, in this situation, there's only one "SingletonLock" - not the textbox deadlock situation where you have lock(LockA) and lock(LockB) with two threads locking in reverse order.
dev
modified 29-Nov-12 20:23pm.
|
|
|
|
|
You may have only one lock instruction, but there is another lock.
The Invoke itself is a kind of lock. It will wait until the action finishes. That's why it dead-locks (and the BeginInvoke does not, as it does not wait).
|
|
|
|
|
Hi
Regarding my service class attribute, [EnableClientAccess(RequiresSecureEndpoint = true)], I was wondering if it was possible to change the value of RequiresSecureEndpoint based on a value I can set in the config file. e.g.
<appSettings>
<add key="RequireSSL" value="True" />
</appSettings>
Thanks
|
|
|
|
|
I have the following set-up:
1. ViewModel:
...
public ICommand LoadSomeViewCommand;
public SomeViewModel(IRegionManager regionManager, IUnityContainer container)
{
this._regionManager = regioinManager;
this._container = container;
LoadCommand = new RelayCommand(new Action<object>(LoadSomeViewExecute), new Predicate<object>(CanLoadExecute));
}
...
private void LoadSomeViewExecute(object obj)
{
IRegion mainRegion = _regionManager.Regions[RegionNames.MainRegion];
foreach (var v in mainRegion.Views)
{
mainRegion.Remove(v);
}
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(SomeNewView));
}
private bool CanLoadExecute(object obj)
{
return true;
}
in the View.cs:
public SomeView(IRegionManager regionManager, IUnityContainer container)
{
InitializeComponent();
this.DataContext = new SomeViewModel(regionManager, container);
}
public SomeViewModel ViewModel
{
get { return (SomeViewModel)this.DataContext; }
}
and in xaml:
...
<StackPanel grid.Row="2">
<Button Content="Load"
Command="{Binding LoadCommand}"/>
...
</StackPanel>
When I click the button to load another component, the LoadCommand has been set in the constructor but never seems to be called on the button click.
I have been converting a VB project to C# to try and learn the language and maybe I have missed something in the translation.
I have other containers injecting into the shell that don't use Command calls that are working fine.
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
Dunno if you want these kinds of comments, so feel free to ignore them if you are offended , but your question IS answered below.
1) Bad practice to litter your code with 'this'. It's not needed as its implied.
2) Bad practice to use an interface to reference a concrete class inside of the class itself (public ICommand LoadSomeViewCommand)... its a RelayCommand, not an ICommand. You should only pass it around externally as an ICommand.
3) Your implementation of RelayCommand isn't correct. You should not need all that new Action, new Predicate garbage.
4) Your non-generic RelayCommand should not take any params. RelayCommand<T> is the one that takes a param and that one should be type safe. Don't pass in an object, pass in the real type.
5) *THE ANSWER TO YOUR QUESTION* You can't databind to a variable. Only properties.
6) If you are using UnityContainer, or any other DI container. USE IT. In your SomeView contructor, you have the unity container reference, but aren't using it to create the object.
7) Better to use an attached property to set your data context, so you get rid of all the hand wiring with a code behind.
8) Stop using var's for simple types. This isn't JavaScript . Vars have specific uses, this isn't one of them.
|
|
|
|
|
Cheers, i am not easily offended and want to learn this the correct way - very hard without someone to bounce off. As I said, this is from a VB project I am converting to try nd get the hang of the language.
You have given me a few things to work on,and probably learn from.
Thanks
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
SledgeHammer01 wrote: 1) Bad practice to litter your code with 'this'. It's not needed as its implied.
One of the default rules in FXCop or style cop or some such horror dictates the use of this. EVERYWHERE, I do find it useful for limiting the scope of intellisense but it really feels like using the VB me. which I still cringe at!
Oh and if I remember correctly Andy is a Kiwi living in Oz, the bugger has to have a thick skin and anyone using VB grows one naturally!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Andy is a Kiwi living in Oz, the bugger has to have a thick skin
Yes, and I know Mick Martin to drink with!
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
Andy_L_J wrote: I know Mick Martin to drink with
Having not yet had this experience and only dealt with his pleasantly abrasive online personality I do look forward to the opportunity when I next hit Sydney. As I now visit Cairns instead I don't know when this will happen though.
I have an ebook (somewhere) I used when moving from VB to C#, it helped with the syntax differences, let me know if you are interested.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Sometimes I'll type "this" if I don't remember the prop name, but I'll delete the this afterwards. I use a leading underscore (which Andy did) on class member variables. That differentiates member variables from local variables. I think very few people agree on formatting / style issues . In my last job, my team lead insisted everybody format the code with 3 spaces. It took me a while to convince him that nobody else likes 3 spaces and if he went to tabs, then everybody could have it how they wanted without affecting the code. He still put up a fight. Only once I showed him that practice in action and how SCC still saw it as exactly the same did the light bulb finally come on.
|
|
|
|
|
My pet hates are underscores, capitalisation and anyone not using TAB set you = 2 spaces (SSMS uses 8 ).
Even if you use tabs and the size of the tabs are different it can totally screw up the formatting when changing developer, irritating to say the least.
Never underestimate the power of human stupidity
RAH
|
|
|
|