XAML How to get a project name - wpf

Im learning XAML with microsoft visual studio 2013 wpf application.
I want to make a textblock display my Project Name from a some kind of resource(?) - I want to make a template :) .
Thank you for help in advance :) .

string name = Assembly.GetEntryAssembly().GetName().Name;
or
string name = Assembly.GetExecutingAssembly().GetName().Name;
Alternatively, you can get the Assembly object from any known type in the assembly:
Assembly assy = typeof({class name here}).Assembly;
This also allows another option to get the the name only:
string name = typeof({class name here}).Assembly.GetName().Name;
Here's the link

Related

Covert a String to an Object which has a variable name

I searched for two hours, here on Stackoverflow and on other forums. But i can't find a solution for my problem. I have to be able to change the properties of an object that has a name that I don't know. Now i try to explain better:
The user drag some files in a form, and i get in a array() all the paths of the dragged files. For each path in files() i add to a panel a usercontrol that is the interface of an uploader. (My application it's kind of an uploader). Good, imagine that the user dragged 4 files, i have 4 different usercontrols, named "Uploader1", "Uploader2", "Uploader3" and "Uploader4". I need to change the text of a label in the uploader1, but i can't write:
Uploader1.LabelExample.Text = "Example"
Becouse it doesn't exist! (Not yet!)
So i tryed this method.
Dim UploadCounter as Integer = 1
Dim CurrentUploader = CType(Panel.Controls("Uploader" & UploaderCounter.ToString), UploadBanner)
CurrentUploader.LabelExample.Text = "Example"
I write the same with DirectCast and TryCast, but nothing.
I try also:
For Each Uploader With{.Name = "Uploader1"} as UploaderControl in Panel.Controls
Uploader.LabelExample.Text = "Example"
Next
I searched everywhere for "convert string to an object in vb.net" but i can't find anything that work! They all return "System.NullReferenceException: 'Object reference not set to an instance of an object.'"
Sorry for my bad bad english, thanks for all that will help me! need really!

F# quotations on Windows Phone

I'm using Daniel Mohl's F# templates for Windows phone, but it seems the bundled FSharp.Core doesn't have some of the quotations code. I'm trying to port this code from regular .NET:
open System.ComponentModel
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
[<AbstractClass>]
type ViewModelBase() =
let propertyChanged = new Event<_, _>()
let toPropName expr =
match expr with
| PropertyGet(a, b, list) -> b.Name
| _ -> failwith "Unsupported: " + expr.ToString()
interface INotifyPropertyChanged with
[<CLIEvent>]
member x.PropertyChanged = propertyChanged.Publish
member x.NotityPropertyChanged expr =
propertyChanged.Trigger(x, new PropertyChangedEventArgs(toPropName expr))
But the compiler complaints about Microsoft.FSharp.Quotations.Patterns and PropertyGet. It seems it doesn't even know the Expr type.
Any idea on how to solve this?
I replaced the FSharp.Core file that comes in the template by the one that comes in the F# April 2011 CTP in the WindowsPhone7\Silverlight\4.0\bin folder, and with this version it now compiles fine
I've compared FSharp.Core.dll from Template you've mentiond and those one which is referenced if you create a F# Silverlight library with .Net Reflector and they are different! :) Thouse one which added to template's dependencies folder doesn't have Quotations.
So my first two thoughts is either add F# SCL and create your view model there or not to use this template at all. But I actually like this template or how it looks at least... so thanks you for the mentioning it anyway :)

Reflection error when using F# sprintf "%A" on Windows Phone

I have a set of F# record types like this:
type Course =
{ Id : int
Title : string
Instructor : string
Duration : string
StartDate : string
IconUrl : string
Url : string
LectureSections : LectureSection list }
and LectureSection =
{ Title : string
Completed : bool
Lectures : Lecture list }
and Lecture =
{ Title : string
VideoUrl : string }
and at some point I call
sprintf "%A" course
where course is an instance of the Course record
On a regular .NET project this works fine, but on a Windows Phone 7.1 / Silverlight 4 F# project (I'm using Daniel Mohl's templates), I get this error:
Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.
The problem seems to be the lists. Does anyone know of any way around this problem?
The templates should come with a custom built FSharp.Core.dll that disable features that are not available on Windows Phone. Are you sure you are compiling against this dll, and not the Windows PC one?
I had similar problems with Xbox360 and XNA. The F# team sent me a dll suitable for use for the Xbox360, along with some brief instructions on the settings used to build the dll.
Here is the propertygroup we've used to compile FSharp.Core:
<PropertyGroup Condition="'$(TargetFramework)'=='Xbox360\CompactFramework\3.7'">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Xbox 360</XnaPlatform>
<XnaProfile>HiDef</XnaProfile>
<XnaCrossPlatformGroupID>a8d70e6b-9a75-4aec-80f8-62cf373f7368</XnaCrossPlatformGroupID>
<XnaOutputType>Game</XnaOutputType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DefineConstants>$(DefineConstants);FX_NO_ARRAY_LONG_LENGTH;FX_NO_DEBUG_PROXIES;FX_NO_EXIT;FX_FSLIB_IOBSERVABLE;FX_NO_WEB_CLIENT;FX_NO_WEB_REQUESTS;FX_NO_CHAR_PARSE;FX_NO_DEFAULT_DEPENDENCY_TYPE;FX_SIMPLE_SECURITY_PERMISSIONS;FX_NO_TRUNCATE;FX_NO_CULTURE_INFO_ARGS;FX_NO_REFLECTION_MODULE_HANDLES;FX_NO_OPERATION_CANCELLED;FX_NO_TO_LOWER_INVARIANT;FX_NO_EXIT_CONTEXT_FLAGS;FX_NO_BASED_ARRAYS;FX_NO_DOUBLE_BIT_CONVERTER;FX_NO_BINARY_SERIALIZATION;FX_NO_ASCII_ENCODING;FX_NO_DEFAULT_ENCODING;FX_NO_FILE_OPTIONS;FX_NO_NONBLOCK_IO;FX_NO_COMMAND_LINE_ARGS;FX_NO_ENVIRONMENT;FX_NO_PROCESS_START;FX_NO_APP_DOMAINS;FX_NO_PROCESS_DIAGNOSTICS;FX_FSLIB_STRUCTURAL_EQUALITY;FX_FSLIB_LAZY;FX_FSLIB_TUPLE;FX_NO_REFLECTION_EMIT</DefineConstants>
<Tailcalls>false</Tailcalls>
<!-- It would be better to use MSBuild resolution here, but the TargetFrameworkIdentifier etc. aren't set up quite correctly as yet -->
<OtherFlags>$(OtherFlags) --simpleresolution -r:"C:\Program Files\Microsoft XNA\XNA Game Studio\v4.0\References\Xbox360\mscorlib.dll"</OtherFlags>
</PropertyGroup>
and the new .targets we use:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets" Condition="'$(TargetFramework)'=='Xbox360\CompactFramework\3.7'"/>
The dll they sent me was working fine, and I never had to use these instructions, but they might be useful to someone who wants to build an FSharp.Core.dll for a new platform. Note in particular the DefineConstants part.

Database.open - 'The name 'database does not exist in the current context'

I followed the following tutorial to help me create a datagrid (http://www.asp.net/web-pages/videos/aspnet-razor-pages/displaying-data-in-a-grid), however, I keep getting the error in the title under the word database. I've tried replacing it with the name of my database (Products) however that didnt work. Does anyone know why it could be happening? This piece of code sits at the top of my view page:
#{
var _db = database.open("Products");
var selectQueryString = "SELECT * FROM Products ORDER BY DateBought, SortOrder";
var data = _db.query(selectQueryString);
var grid = new WebGrid(Model);
}
When I check the values I receive in the drop down menu when I type var _db = datab.. I only have the following available:
Databinding, Databinder, DatabindingCollection, Databindinghandlerattribute, databindingliteralcontrol, Designerdataboundliteralcontrol, Idatabindingsassessor
You need to add a Reference to WebMatrix.Data.dll
Database class is part of WebMatrix.Data there for is only available through that dll.
You can find WebMatrix.Data.dll in [Program Files Directory]\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies or v2.0\Assemblies regarding the version you have installed.
I had the same error and I found this solution that worked for me:
http://www.w3schools.com/aspnet/webpages_database.asp
It seems that Webmatrix2 doesn't include the said .dll by default. I only had to download the nuget package from Webmatrix's gallery and it worked.
I hope it helps others.

How-to: Load a type from a referenced assembly at runtime using a string in Silverlight

I have tried this, specifying the assembly name:
Type.GetType(string.Format("{0}.{1}, {0}", typeToLoad.AssemblyName, typeToLoad.ClassName));
Which throws the following:
The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest
Trying the same without including the trailing assembly name like this:
Type.GetType(string.Format("{0}.{1}", typeToLoad.AssemblyName, typeToLoad.ClassName));
-- returns null.
So, I am looking for a way to instantiate a class by providing its fully qualified name in Silverlight 4.0.
Any ideas would be greatly appreciated, Thanks.
I had the same issue and it worked when I tried the assembly qualified type name in the following format :
", , Version="", Culture=, PublicKeyToken="

Resources