Twitter Character Counting - twitter

I want to implement a remaining character count feature for Twitter Twitt TextBox in Windows Phone 8 & Windows store 8.1.
Twitter limits Tweet length to 140 characters.If Textbox Text length exceeds 140 char,I'm not allowing user to twitt that text message.
If user enters any URLs in textBox,twitter api considers that Url length as 22 or 23.
How to implement a remaining character count feature with Urls?.If any method is available in Twiteer Api?
https://dev.twitter.com/overview/api/counting-characters
https://dev.twitter.com/overview/t.co
Thanks in advance.

This is a combination of simple, and surprisingly difficult.
So, I solved this with a behavior; I call it the SocialTextBoxBehavior.
You can download the source here: http://codepaste.net/j4ry9v
It easily supports a UI like this:
I certainly tested it to make sure it works. It seems to.
I added some nice properties you can bind back to your viewmodel:
MaxLength - you would likely set this to 140
MinLength - this is up to you, it defaults to 5
UrlLength - in your question you indicated 22 or 23 (it's a scalar value)
CurrentLength - current, adjusted text length; this is updated as the user types
CurrentRemaining - current, adjusted remaining; this is updated as the user types
IsValid - ensuring CurrentLength is between constraints; this is updated as the user types
The syntax to use the behavior is pretty straight-forward. I hope you think so.
Like this:
<StackPanel>
<TextBox Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<Interactivity:Interaction.Behaviors>
<Behaviors:SocialTextBoxBehavior x:Name="TwitterBehavior" />
</Interactivity:Interaction.Behaviors>
</TextBox>
<TextBlock Margin="0,10" DataContext="{Binding ElementName=TwitterBehavior}">
<Run Text="{Binding CurrentLength}" />
<Run Text="character(s) typed." />
<LineBreak />
<Run Text="{Binding RemainingLength}" />
<Run Text="character(s) remaining." />
<LineBreak />
<Run Text="{Binding MaxLength}" />
<Run Text="character(s) limit." />
<LineBreak />
<Run Text="Can submit? " />
<Run Text="{Binding IsValid}" />
</TextBlock>
<Button IsEnabled="{Binding IsValid, ElementName=TwitterBehavior}" />
</StackPanel>
Best of luck!

Related

Posting Multiple Images to Twitter with Coldfusion using MonkehTweet

I am using MonkehTweet Coldfusion wrapper for Twitter Authentication. I have everything up working, but i cannot get my head around posting multiple images using the PostUpdateWithMedia function. I am relatively new to coldfusion, and learning it along the way. A simple call to PostUpdateWithMedia(status="", media="") would post to Twitter with an image, but how can i use this to post multiple images. The PostUpdateWithMedia function from MonkehTweet is,
<cffunction name="postUpdateWithMedia" access="public" output="false" hint="Updates the authenticating user's status. Request must be a POST. A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.">
<cfargument name="status" required="true" type="String" hint="The text of your status update. URL encode as necessary. Statuses over 140 characters will be forceably truncated." />
<cfargument name="media" required="true" type="string" hint="Up to max_media_per_upload files may be specified in the request, each named media[]. Supported image formats are PNG, JPG and GIF. Animated GIFs are not supported." />
<cfargument name="possibly_sensitive" required="false" type="boolean" default="false" hint="Set to true for content which may not be suitable for every audience." />
<cfargument name="in_reply_to_status_id" required="false" type="String" hint="The ID of an existing status that the update is in reply to." />
<cfargument name="lat" required="false" type="String" hint="The location's latitude that this tweet refers to." />
<cfargument name="long" required="false" type="String" hint="The location's longitude that this tweet refers to." />
<cfargument name="place_id" required="false" type="String" hint="A place in the world. These IDs can be retrieved from geo/reverse_geocode." />
<cfargument name="display_coordinates" required="false" type="String" hint="Whether or not to put a pin on the exact coordinates a tweet has been sent from." />
<cfargument name="checkHeader" required="false" type="boolean" default="false" hint="If set to true, I will abort the request and return the response headers for debugging." />
<cfargument name="timeout" required="false" type="string" default="#variables.instance.timeout#" hint="An optional timeout value, in seconds, that is the maximum time the cfhttp requests can take. If the time-out passes without a response, ColdFusion considers the request to have failed." />
<cfset var strTwitterMethod = '' />
<cfset arguments["media[]"] = arguments.media />
<cfset structDelete(arguments,'media') />
<cfset strTwitterMethod = getCorrectEndpoint('api') & 'statuses/update_with_media.json' />
<cfreturn genericAuthenticationMethod(timeout=getTimeout(), httpURL=strTwitterMethod,httpMethod='POST', parameters=arguments, checkHeader=arguments.checkHeader) />
</cffunction>
I have tried passing in multiple files as,
PostUpdateWithMedia(status="", media="", media=""); but it didnot work. But, I am passing in the multiple media arguments wrong. Can someone help me with how to pass in multiple media arguments.
Unfortunately, MonkehTweet does not include support for the Twitter API media/upload endpoint, which is required for multi-image Tweets - it only supports the deprecated statuses/update_with_media, which still works, but only supports a single image. I also noticed that the code still refers to 140 character Tweets, so it probably has not been updated for some time. I'm not aware of an alternative ColdFusion wrapper for the API, either, so this is something you would need to build for yourself.

Setting TFS field as readonly based on area path

I have custom TFS form with a text field comment. I want this field to be readonly for most of the area paths except 4. How can I add condition to set the field as read only?
basically, when the area id is 1,2,3,4 the comment field should not be readonly else it should be readonly.
I tried the following, but it didn't work
<FIELD name="Comment" refname="test.test.comment" type="Integer">
<WHENNOT field="System.AreaId" value="1">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="2">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="3">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="4">
<READONLY />
</WHENNOT>
</FIELD>
I dont want to write when conditions because these 4 are constant and I have about 40 other area ids which keeps increasing.
No, "And" multiple "WHENNOT" conditions doesn't work. See: Work Item state change rules in TFS - Any way to use "AND"s or "OR"s?
So, instead of using work item rules, you need to work with custom work item control. Determine when to set Comment filed to be readonly via using TFS API. Check this link for the details on how to work with custom work item control: https://witcustomcontrols.codeplex.com/

WPF XAML Binding

I have 2 tables Main and Maintest. I am using nhibernate to pull data from database and am joining 2 tables to fetch the fields from both.Now my final object has data from both the tables. Now when I debug my app I can see that I have 2 records from Main and 5 records from Maintest. But somehow I am not able to display records from Maintest.
<DataTemplate x:Key="myTaskTemplate">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding FirstName}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<StackPanel>
<ListBox ItemsSource="{Binding Main}" ItemTemplate="{StaticResource myTaskTemplate}" Height="200" Width="200" />
<toolkit:DataGrid ItemsSource="{Binding Main.Maintest}" Margin="3"
AutoGenerateColumns="False"
CanUserAddRows="False" CanUserDeleteRows="False"
CanUserReorderColumns="False" CanUserResizeRows="False">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Header="#"
Binding="{Binding Number}"/>
<toolkit:DataGridTextColumn Header="Airline"
Binding="{Binding Code}"/>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</StackPanel>
NHibernate Mapping:
<class name="Main" lazy="false">
<id name="ID" type="Int32">
<generator class="native"/>
</id>
<set name="Maintest" inverse="true">
<key column="Ticket" on-delete="cascade" />
<one-to-many class="Segment" />
</set>
....
I able to display listbox record but not toolkit records. Although I can see that for each Main record my object does have 3 or more records in Maintest.
Something doesn't add up...
ListBox.ItemsSource takes an IEnumerable of some kind - which means the property Main must be some kind of IEnumerable?
So, if what you're looking for is a Master-Detail kind of view - you need to change the XAML for the two controls like this - everything else should be fine:
<ListBox Name="Main" .../>
<toolkit:DataGrid ItemsSource="{Binding SelectedItem.Maintest,ElementName=Main}" .../>
This will make the DataGrid bind to the MainTest property of whatever obejct is selected in the ListBox.
Look to Bea Costa if you really need to get spiffy with Master-Detail scenarios.
Hope this helps!

WPF Binding Button.Command in ControlTemplate to property of ViewModel

My ViewModel has a property called Commands which is of type IDictionary.
For my data grid I have created a ControlTemplate for one of the fields using a button as follows:
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Button Style="{DynamicResource btnRemove}" Width="14" Height="14"
Content="{TemplateBinding Content} "
CommandParameter="{Binding ViewID}"
Command="{Binding Commands[AcknowledgeErrorCmd]}" />
<ControlTemplate.Triggers>
</ControlTemplate.Triggers>
</ControlTemplate>
Clicking on the button does nothing which tells me the binding did not work. However, an unstyled button added to the toolbar of the same window hosting this grid works, binds properly to this command. I guess my question is:
Hw do I bind the command property of a button used in a ControlTemplate to a ViewModel?
TIA.
I am not sure what the problem is but try to debug your solution and look into the output window with Debug selected in the combobox and you will see the errors that occur during binding. Maybe this will help you to the solution.
Provide me the error as a comment on this post if you don't understand it.
I did this instead:
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Border >
<TextBlock Margin="5">
<Hyperlink
CommandParameter="{Binding ElementName=root, Path=DataContext.ViewID}"
Command="{Binding ElementName=root, Path=DataContext.Commands[AcknowledgeErrorCmd]}">
<TextBlock Text="Acknowledge"/>
</Hyperlink>
</TextBlock>
</Border>
</ControlTemplate>
and that works fine. It may be related to the post Viko provided.

Strange Behaviour in DataGrid SilverLight 3 Control

Here is the my Xaml Code. Here I have changed the Foreground of the cell depending on the current age of the person.
<data:DataGridTemplateColumn Header="First Name" Width="150" MinWidth="150" CanUserReorder="False" SortMemberPath="FirstName">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<TextBlock Foreground ="{Binding Path=DateOfBirth,Mode=OneWay,Converter={StaticResource CellColor}}" Text="{Binding FirstName}" ToolTipService.ToolTip="{Binding FirstName}" FontFamily="Arial" FontSize="11" VerticalAlignment="Center" Margin="5,0,0,0" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTextColumn Foreground ="{Binding Path=DateOfBirth,Mode=OneWay,Converter={StaticResource CellColor}}" Header="Last Name" Width="150" MinWidth="150" Binding="{Binding LastName}" CanUserSort="True" IsReadOnly="True" CanUserReorder="False"/>
When I run the above code it return following Exception
AG_E_PARSER_BAD_PROPERTY_VALU
My question is that when I remove the Foreground converter from the DataGridTextColumn Column it runs fine As the Foreground converter is applied in the DataGridTemplateColumn Column which will not through excepction. But when I used same Converter to the DataGridTextColumn it throw execption why, can anyone know why is th
is behaviour
thanks in advance.
Sorry Josh Einstein Here is the my return value from the converter
if (intAge > 25)
return new SolidColorBrush(Colors.Red);
else
return new SolidColorBrush(Colors.White);

Resources