Divide timespan by 2?
I think you want to do this: TimeSpan span = sunset-sunrise; TimeSpan half = new TimeSpan(span.Ticks / 2); DateTime result = sunrise + half; It can be written in one line if you want.
I think you want to do this: TimeSpan span = sunset-sunrise; TimeSpan half = new TimeSpan(span.Ticks / 2); DateTime result = sunrise + half; It can be written in one line if you want.
Silverlight for WP7 does not support the syntax you’ve listed. Do the following instead: <TextBox TextChanged=”OnTextBoxTextChanged” Text=”{Binding MyText, Mode=TwoWay, UpdateSourceTrigger=Explicit}” /> UpdateSourceTrigger = Explicit is a smart bonus here. What is it? Explicit: Updates the binding source only when you call the UpdateSource method. It saves you one extra binding set when the user leaves … Read more
Silverlight has the Uri.EscapeUriString and Uri.EscapeDataString which can be used to URL-encode portions of a URI such as query strings and path components and such. Even in the desktop framework, you should never take a dependency on System.Web.dll just for HttpUtility, although many developers still do it. This is bad for 3 reasons. The assembly … Read more
Old question but if you are using C# 5 you can have a generic execute class by creating a TaskCompleteSource that resturns a Task of T. Your code could look like this: public Task<T> ExecuteAsync<T>(RestRequest request) where T : new() { var client = new RestClient(); var taskCompletionSource = new TaskCompletionSource<T>(); client.BaseUrl = BaseUrl; client.Authenticator … Read more
In WMAppManifest.xml you’ll find the following. <Tasks> <DefaultTask Name=”_default” NavigationPage=”MainPage.xaml” /> </Tasks> Change as appropriate.
c++/cli can theoretically be used with WPF/Silverlight using the trick of replacing the C# generated from the XAML with a macro definition that can be used inside the main class in a code behind file. I worked out this technique but haven’t had the motivation to take it beyond theory – I’m quite happy mixing … Read more
What you need to do is create a button template that modifies the Pressed visual state. In blend, select your button, click the menu item “Object”->”Edit Template”->”Edit a Copy…” and a new template is created. In the States window, select the Pressed visual state in the CommonStates visual state group. Now select ButtonBackground in the … Read more
I have encountered this before, TemplateBinding does not work for custom dependency properties on controls. See these related questions: issues with template binding and binding of custom component TemplateBinding does not work in certain cases(when using TranslateTransform) I have always used this instead: {Binding MyProperty, RelativeSource={RelativeSource TemplatedParent}} It is semantically the same as TemplateBinding, and … Read more
There are two potential causes of this. The most common is the x:Class doesn’t match up with the MainPage.xaml namespace. Make sure that x:Class in MainPage.xaml has the correct namespace. The second most common cause of this problem is that the “Build Action” is not set to “Page” for MainPage.xaml!
Make sure that the image properties ‘build to action‘ is Content.