Showing posts with label weird solutions. Show all posts
Showing posts with label weird solutions. Show all posts

Thursday, September 16, 2010

Popcorn Hour and Windows 7

To watch any video on my TV I use networked media tank (NMT) called Popcorn Hour. It does not make any sound (I did not install HDD in it) and it can access any shared resource across the network.

But recently I faced one serious problem - I upgraded to Windows 7 on one of my PCs (which btw have the largest storage space in my apartment) and I was not able to connect to it with my NMT. So I started to look for solutions.

Turned out that this problem is widely known and discussed, but usually it is solved somehow...easier than in my case, so I think that edition of Windows 7 matters in this case. (in my case it's Windows 7 Ultimate Edition)

After some investigation turned out that the exact solution for my problem is to disable this setting in Local security policy: "Restrict anonymous access to Named Pipes and Shares"

To do that you should go to "Control Panel/Administrative Tools/Local Security Policy/Local Policies/Security Options/Network Access: Restrict anonymous access to Named Pipes and Shares" and set it to Disabled.

Warning: Changing that setting could compromise security of your PC, so if your PC is not inside some private home network, than you should not do that change.

Also if you still cannot access your PC from NMT (or any other linux-based device), then probably this will help: http://anime.aoselectronics.com/wordpress/how-to-access-windows-7-shares-from-network_181/

Friday, April 4, 2008

Weird solutions: Ho can I force WPF control to rerender itself.

Today I found out some strange solution for forcing control to invalidate itself.

It turned out that by default control invalidates itself only in case it's render size has been changed, his visual parent has been changed, or some of it's dependency properties with AffectsRender option set is changed. (also there are some other weird cases when control suddenly decides to rerender it's appearance)

So I decided that maybe I can use FrameworkElement's ability to react to the AffectsRender option - I implemented the attached dependency property, and tried setting it to some rendom values on an object I needed to invalidate...and it worked :)

Here is some sample class, that could be used to implement such workaround:


public class RenderingHelper : DependencyObject
{
private static int s_last = 0;

public static int GetForceRerender( DependencyObject obj )
{
return (int)obj.GetValue( ForceRerenderProperty );
}
public static void SetForceRerender( DependencyObject obj, int value )
{
obj.SetValue( ForceRerenderProperty, value );
}

public static readonly DependencyProperty ForceRerenderProperty = DependencyProperty.RegisterAttached( "ForceRerender", typeof( int ), typeof( RenderingHelper ),
new FrameworkPropertyMetadata( 0, FrameworkPropertyMetadataOptions.AffectsRender ) );


public static void InvalidateRender( Visual target )
{
SetForceRerender( target, s_last++ );
}
}



You should keep in mind that invalidation of a visual calls it's OnRender method and recreates only part of the elements visual graph. All Visual's children are left the same, so if you need to invalidate the appearance of the entire visual subtree, you should add FrameworkPropertyMetadataOptions.Inherits to the property options.

Friday, March 14, 2008

Why InvalidateZOrder is not public???

The worst case of what you can implement on WPF is custom control. In this case you have to use most of the extensebility of the framework, and it turns out that it is just, well, non-extensible...

Today it turned out that there is no way to change the z-order of the element if it's parent is not a Panel, and there is no way I can use Panel as a parent because it tries to steal my logical children :(

It also turned out that there is no way to change z-order without making this:

foreach( Visual child in children )
{
RemoveVisualChild( child );
AddVisualChild( child );
}

And that could be avoided if a method of a Visual, called InvalidateZOrder, would not be internal :(