Search This Blog
Tuesday, November 29, 2011
Replace/change headlights’ light bulb in Opel Corsa C 2006 1.3 CDTI
Instructions:
1. Hang the wire on the headlight’s bottom’s hook
2. Line-up the wire with the bulb's cavities
3. Pressing the wire to the bulb’s cavities widen the upper part and THEN push it toward the bulb. After pushing the wire start squeezing it together.
C# DependencyProperty assign List or Array; C# convert List to DependencyObject
Actually if you’re trying to set a List<object> to a dependency property you don’t need to do any of these things. Just make your base class inherit from DependencyObject and use SetValue() method.
public class YourClass : DependencyObject
{
public static DependencyProperty SCProperty = DependencyProperty.RegisterAttached("SC", typeof(List<SD>), typeof(DataGrid), new PropertyMetadata(SCChanged));
public static void SetSortedColumns(DependencyObject dp, object value)
{
dp.SetValue(SCProperty, value);
}
public static object GetSortedColumns(DependencyObject dp)
{
return dp.GetValue(SCProperty);
}
private static void SCChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { }
//REST OF YOUR CODE
[.....]
//REST OF YOUR CODE
private void SomeMethod()
{
SetValue(SCProperty, newValue_List);
}
}
Monday, November 28, 2011
Silverlight capturing key clicks; Silverlight capturing special key clicks; Silverlight Keyboard.Modifiers class
To capture special key clicks (like ctrl, alt and shift modifier key clicks) one does not have to use KeyDown & KeyUp method. There is a class Keyboard which is available in Silverlight as well. Use Keyboard.ModifierKeys to accomplish desired effect.
Sample usage:
if (Keyboard.Modifiers.Equals(System.Windows.Input.ModifierKeys.Control))
{
//do something
}
Keyboard.ModifierKeys allows a bitwise combination of its members.
To capture other key clicks one needs to write a static class which will be available in the whole application.
The example KeyPressMonitor class is available here.
Wednesday, November 23, 2011
C#–Never place an event inside a struct; C# event is always null inside a struct
When you write something similar to:
namespace XXX
{
public struct SomeStruct
{
public event SomeDelegate SortDirectionChanged;
}
public delegate void SomeDelegate(SomeInfo input);
}
then SortDirectionChanged event will always be null.
So when you try to set a delegate to the event like this:
var sth = new SomeStruct();
sth.SortDirectionChanged += SomeMethodServingEventCall;
SortDirectionChanged will be null when you'll try to pass on the struct. (when you check it with a debugger right after the assignment it will appear to be ok – strange). Use class instead.
Monday, November 21, 2011
C# change DataTemplate binding; C# change binding inside DataTemplate from code
The main idea is to have a DataTemplate in a separate XAML file but change Binding inside this DataTemplate from source code.
Create a xaml file, insert the DataTemplate and change Build action to: Embedded Resource (Copy to Output Directory: Do no copy - it is not necessary). The Assembly.GetManifestResourceStream() loads our resource as string. We can replace bindings then. XamlReader.Load() will convert string to DataTemplate. The Assembly.GetManifestResourceNames() will give you registered embedded resource name if something does not work.
DataTemplate mycolumnDataTemplate = null;
var dataTemplateStream = new ViewDescription().GetType().Assembly.GetManifestResourceStream("Some.Namespace.SomeReosurceName.xaml");
//Load the DataTemplate.
string dataTemplateString = new System.IO.StreamReader(dataTemplateStream).ReadToEnd();
dataTemplateString = dataTemplateString.Replace("[0]", browserColumn.ColumnName);
mycolumnDataTemplate = XamlReader.Load(dataTemplateString) as DataTemplate;
SomeReosurceName.xaml:
<DataTemplate
x:Key="CustomDataGridColumnTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock Name="CustomTextBox" Text="{Binding [0]}" Margin="0,4,0,0"/>
</DataTemplate>
Friday, November 11, 2011
Android change dialog width; Android set width of a custom Dialog
When one creates custom dialogs in Android there is a problem with setting the width of the dialog to fill the entire available space. I described custom dialog creation here. This sample shows how to set the width of the custom dialogs in Android:
loginDialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
OR
loginDialog.getWindow().setLayout(600, 400);
Android open dialog; Unable to start activity ComponentInfo Unable to add window token null is not for an application
When I tried to open a dialog with getApplicationContext() this error prevented me from accomplishing the goal:
“Unable to start activity ComponentInfo Unable to add window token null is not for an application”
Dialog loginDialog = new Dialog(this);
loginDialog.setContentView(R.layout.loginlayout);
loginDialog.setTitle(R.string.loginScreenHeader);
loginDialog.show();
DO NOT USE:
Context mContext = getApplicationContext();
Dialog loginDialog = new Dialog(mContext);
Android find control reference in activity; reference control from code
There is a simple method that allows us to find a control from the code-behind (android’s activity): findViewById();
Remember to use setContentView(someLayout) before calling the find function to allow the controls to build themselves.
Find a button and bind an acion to it:
final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//some action
}
});
Saturday, November 5, 2011
Check torrent port; how to check if your torrent port is open; check if your torrent port is forwarded properly
So what should you do if you use a different torrent client? - e.g. Transmission or a torrent client on your router.
There is still an online solution for this but it's hard to find the proper site. One of the services that actually works is:
http://www.canyouseeme.org/
Have fun with it.